Skip to content

Commit 555b4ef

Browse files
Jiri Slabygregkh
authored andcommitted
vt: selection, localize use_unicode
use_unicode needs not be global. It is used only in set_selection_kernel and sel_pos (a callee). It is also always set there prior calling sel_pos. So make use_unicode local and rename it to plain shorter "unicode". Finally, propagate it to sel_pos via parameter. Signed-off-by: Jiri Slaby <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 101f227 commit 555b4ef

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

drivers/tty/vt/selection.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ extern void poke_blanked_console(void);
4141
/* Variables for selection control. */
4242
/* Use a dynamic buffer, instead of static (Dec 1994) */
4343
struct vc_data *sel_cons; /* must not be deallocated */
44-
static int use_unicode;
4544
static volatile int sel_start = -1; /* cleared by clear_selection */
4645
static int sel_end;
4746
static int sel_buffer_lth;
@@ -64,9 +63,9 @@ static inline void highlight_pointer(const int where)
6463
}
6564

6665
static u32
67-
sel_pos(int n)
66+
sel_pos(int n, bool unicode)
6867
{
69-
if (use_unicode)
68+
if (unicode)
7069
return screen_glyph_unicode(sel_cons, n / 2);
7170
return inverse_translate(sel_cons, screen_glyph(sel_cons, n),
7271
0);
@@ -194,6 +193,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
194193
int i, ps, pe;
195194
u32 c;
196195
int ret = 0;
196+
bool unicode;
197197

198198
poke_blanked_console();
199199

@@ -224,7 +224,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
224224
clear_selection();
225225
sel_cons = vc_cons[fg_console].d;
226226
}
227-
use_unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
227+
unicode = vt_do_kdgkbmode(fg_console) == K_UNICODE;
228228

229229
switch (v->sel_mode)
230230
{
@@ -233,21 +233,21 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
233233
new_sel_end = pe;
234234
break;
235235
case TIOCL_SELWORD: /* word-by-word selection */
236-
spc = isspace(sel_pos(ps));
236+
spc = isspace(sel_pos(ps, unicode));
237237
for (new_sel_start = ps; ; ps -= 2)
238238
{
239-
if ((spc && !isspace(sel_pos(ps))) ||
240-
(!spc && !inword(sel_pos(ps))))
239+
if ((spc && !isspace(sel_pos(ps, unicode))) ||
240+
(!spc && !inword(sel_pos(ps, unicode))))
241241
break;
242242
new_sel_start = ps;
243243
if (!(ps % vc->vc_size_row))
244244
break;
245245
}
246-
spc = isspace(sel_pos(pe));
246+
spc = isspace(sel_pos(pe, unicode));
247247
for (new_sel_end = pe; ; pe += 2)
248248
{
249-
if ((spc && !isspace(sel_pos(pe))) ||
250-
(!spc && !inword(sel_pos(pe))))
249+
if ((spc && !isspace(sel_pos(pe, unicode))) ||
250+
(!spc && !inword(sel_pos(pe, unicode))))
251251
break;
252252
new_sel_end = pe;
253253
if (!((pe + 2) % vc->vc_size_row))
@@ -273,12 +273,12 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
273273
/* select to end of line if on trailing space */
274274
if (new_sel_end > new_sel_start &&
275275
!atedge(new_sel_end, vc->vc_size_row) &&
276-
isspace(sel_pos(new_sel_end))) {
276+
isspace(sel_pos(new_sel_end, unicode))) {
277277
for (pe = new_sel_end + 2; ; pe += 2)
278-
if (!isspace(sel_pos(pe)) ||
278+
if (!isspace(sel_pos(pe, unicode)) ||
279279
atedge(pe, vc->vc_size_row))
280280
break;
281-
if (isspace(sel_pos(pe)))
281+
if (isspace(sel_pos(pe, unicode)))
282282
new_sel_end = pe;
283283
}
284284
if (sel_start == -1) /* no current selection */
@@ -309,7 +309,7 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
309309

310310
/* Allocate a new buffer before freeing the old one ... */
311311
/* chars can take up to 4 bytes with unicode */
312-
bp = kmalloc_array((sel_end - sel_start) / 2 + 1, use_unicode ? 4 : 1,
312+
bp = kmalloc_array((sel_end - sel_start) / 2 + 1, unicode ? 4 : 1,
313313
GFP_KERNEL);
314314
if (!bp) {
315315
printk(KERN_WARNING "selection: kmalloc() failed\n");
@@ -322,8 +322,8 @@ int set_selection_kernel(struct tiocl_selection *v, struct tty_struct *tty)
322322

323323
obp = bp;
324324
for (i = sel_start; i <= sel_end; i += 2) {
325-
c = sel_pos(i);
326-
if (use_unicode)
325+
c = sel_pos(i, unicode);
326+
if (unicode)
327327
bp += store_utf8(c, bp);
328328
else
329329
*bp++ = c;

0 commit comments

Comments
 (0)