3838extern void poke_blanked_console (void );
3939
4040/* FIXME: all this needs locking */
41- /* Variables for selection control. */
42- /* Use a dynamic buffer, instead of static (Dec 1994) */
43- struct vc_data * sel_cons ; /* must not be deallocated */
44- static volatile int sel_start = -1 ; /* cleared by clear_selection */
45- static int sel_end ;
46- static int sel_buffer_lth ;
47- static char * sel_buffer ;
48- static DEFINE_MUTEX (sel_lock );
41+ static struct vc_selection {
42+ struct mutex lock ;
43+ struct vc_data * cons ; /* must not be deallocated */
44+ char * buffer ;
45+ unsigned int buf_len ;
46+ volatile int start ; /* cleared by clear_selection */
47+ int end ;
48+ } vc_sel = {
49+ .lock = __MUTEX_INITIALIZER (vc_sel .lock ),
50+ .start = -1 ,
51+ };
4952
5053/* clear_selection, highlight and highlight_pointer can be called
5154 from interrupt (via scrollback/front) */
5255
5356/* set reverse video on characters s-e of console with selection. */
5457static inline void highlight (const int s , const int e )
5558{
56- invert_screen (sel_cons , s , e - s + 2 , 1 );
59+ invert_screen (vc_sel . cons , s , e - s + 2 , 1 );
5760}
5861
5962/* use complementary color to show the pointer */
6063static inline void highlight_pointer (const int where )
6164{
62- complement_pos (sel_cons , where );
65+ complement_pos (vc_sel . cons , where );
6366}
6467
6568static u32
6669sel_pos (int n , bool unicode )
6770{
6871 if (unicode )
69- return screen_glyph_unicode (sel_cons , n / 2 );
70- return inverse_translate (sel_cons , screen_glyph (sel_cons , n ),
71- 0 );
72+ return screen_glyph_unicode (vc_sel .cons , n / 2 );
73+ return inverse_translate (vc_sel .cons , screen_glyph (vc_sel .cons , n ), 0 );
7274}
7375
7476/**
@@ -80,16 +82,16 @@ sel_pos(int n, bool unicode)
8082void clear_selection (void )
8183{
8284 highlight_pointer (-1 ); /* hide the pointer */
83- if (sel_start != -1 ) {
84- highlight (sel_start , sel_end );
85- sel_start = -1 ;
85+ if (vc_sel . start != -1 ) {
86+ highlight (vc_sel . start , vc_sel . end );
87+ vc_sel . start = -1 ;
8688 }
8789}
8890EXPORT_SYMBOL_GPL (clear_selection );
8991
9092bool vc_is_sel (struct vc_data * vc )
9193{
92- return vc == sel_cons ;
94+ return vc == vc_sel . cons ;
9395}
9496
9597/*
@@ -216,13 +218,13 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
216218 return 0 ;
217219 }
218220
219- if (ps > pe ) /* make sel_start <= sel_end */
221+ if (ps > pe ) /* make vc_sel.start <= vc_sel.end */
220222 swap (ps , pe );
221223
222- mutex_lock (& sel_lock );
223- if (sel_cons != vc_cons [fg_console ].d ) {
224+ mutex_lock (& vc_sel . lock );
225+ if (vc_sel . cons != vc_cons [fg_console ].d ) {
224226 clear_selection ();
225- sel_cons = vc_cons [fg_console ].d ;
227+ vc_sel . cons = vc_cons [fg_console ].d ;
226228 }
227229 unicode = vt_do_kdgkbmode (fg_console ) == K_UNICODE ;
228230
@@ -281,47 +283,47 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
281283 if (isspace (sel_pos (pe , unicode )))
282284 new_sel_end = pe ;
283285 }
284- if (sel_start == -1 ) /* no current selection */
286+ if (vc_sel . start == -1 ) /* no current selection */
285287 highlight (new_sel_start , new_sel_end );
286- else if (new_sel_start == sel_start )
288+ else if (new_sel_start == vc_sel . start )
287289 {
288- if (new_sel_end == sel_end ) /* no action required */
290+ if (new_sel_end == vc_sel . end ) /* no action required */
289291 goto unlock ;
290- else if (new_sel_end > sel_end ) /* extend to right */
291- highlight (sel_end + 2 , new_sel_end );
292+ else if (new_sel_end > vc_sel . end ) /* extend to right */
293+ highlight (vc_sel . end + 2 , new_sel_end );
292294 else /* contract from right */
293- highlight (new_sel_end + 2 , sel_end );
295+ highlight (new_sel_end + 2 , vc_sel . end );
294296 }
295- else if (new_sel_end == sel_end )
297+ else if (new_sel_end == vc_sel . end )
296298 {
297- if (new_sel_start < sel_start ) /* extend to left */
298- highlight (new_sel_start , sel_start - 2 );
299+ if (new_sel_start < vc_sel . start ) /* extend to left */
300+ highlight (new_sel_start , vc_sel . start - 2 );
299301 else /* contract from left */
300- highlight (sel_start , new_sel_start - 2 );
302+ highlight (vc_sel . start , new_sel_start - 2 );
301303 }
302304 else /* some other case; start selection from scratch */
303305 {
304306 clear_selection ();
305307 highlight (new_sel_start , new_sel_end );
306308 }
307- sel_start = new_sel_start ;
308- sel_end = new_sel_end ;
309+ vc_sel . start = new_sel_start ;
310+ vc_sel . end = new_sel_end ;
309311
310312 /* Allocate a new buffer before freeing the old one ... */
311313 /* chars can take up to 4 bytes with unicode */
312- bp = kmalloc_array ((sel_end - sel_start ) / 2 + 1 , unicode ? 4 : 1 ,
314+ bp = kmalloc_array ((vc_sel . end - vc_sel . start ) / 2 + 1 , unicode ? 4 : 1 ,
313315 GFP_KERNEL );
314316 if (!bp ) {
315317 printk (KERN_WARNING "selection: kmalloc() failed\n" );
316318 clear_selection ();
317319 ret = - ENOMEM ;
318320 goto unlock ;
319321 }
320- kfree (sel_buffer );
321- sel_buffer = bp ;
322+ kfree (vc_sel . buffer );
323+ vc_sel . buffer = bp ;
322324
323325 obp = bp ;
324- for (i = sel_start ; i <= sel_end ; i += 2 ) {
326+ for (i = vc_sel . start ; i <= vc_sel . end ; i += 2 ) {
325327 c = sel_pos (i , unicode );
326328 if (unicode )
327329 bp += store_utf8 (c , bp );
@@ -339,9 +341,9 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
339341 obp = bp ;
340342 }
341343 }
342- sel_buffer_lth = bp - sel_buffer ;
344+ vc_sel . buf_len = bp - vc_sel . buffer ;
343345unlock :
344- mutex_unlock (& sel_lock );
346+ mutex_unlock (& vc_sel . lock );
345347 return ret ;
346348}
347349EXPORT_SYMBOL_GPL (set_selection_kernel );
@@ -372,26 +374,26 @@ int paste_selection(struct tty_struct *tty)
372374 tty_buffer_lock_exclusive (& vc -> port );
373375
374376 add_wait_queue (& vc -> paste_wait , & wait );
375- mutex_lock (& sel_lock );
376- while (sel_buffer && sel_buffer_lth > pasted ) {
377+ mutex_lock (& vc_sel . lock );
378+ while (vc_sel . buffer && vc_sel . buf_len > pasted ) {
377379 set_current_state (TASK_INTERRUPTIBLE );
378380 if (signal_pending (current )) {
379381 ret = - EINTR ;
380382 break ;
381383 }
382384 if (tty_throttled (tty )) {
383- mutex_unlock (& sel_lock );
385+ mutex_unlock (& vc_sel . lock );
384386 schedule ();
385- mutex_lock (& sel_lock );
387+ mutex_lock (& vc_sel . lock );
386388 continue ;
387389 }
388390 __set_current_state (TASK_RUNNING );
389- count = sel_buffer_lth - pasted ;
390- count = tty_ldisc_receive_buf (ld , sel_buffer + pasted , NULL ,
391+ count = vc_sel . buf_len - pasted ;
392+ count = tty_ldisc_receive_buf (ld , vc_sel . buffer + pasted , NULL ,
391393 count );
392394 pasted += count ;
393395 }
394- mutex_unlock (& sel_lock );
396+ mutex_unlock (& vc_sel . lock );
395397 remove_wait_queue (& vc -> paste_wait , & wait );
396398 __set_current_state (TASK_RUNNING );
397399
0 commit comments