diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c index 3700cd057f27..be8313cdbac3 100644 --- a/drivers/tty/vt/keyboard.c +++ b/drivers/tty/vt/keyboard.c @@ -153,6 +153,7 @@ static int shift_state = 0; static unsigned int ledstate = -1U; /* undefined */ static unsigned char ledioctl; +static bool vt_switch; /* * Notifier list for console keyboard events @@ -414,6 +415,12 @@ void vt_set_leds_compute_shiftstate(void) { unsigned long flags; + /* + * When VT is switched, the keyboard led needs to be set once. + * Ensure that after the switch is completed, the state of the + * keyboard LED is consistent with the state of the keyboard lock. + */ + vt_switch = true; set_leds(); spin_lock_irqsave(&kbd_event_lock, flags); @@ -1255,6 +1262,11 @@ static void kbd_bh(struct tasklet_struct *unused) leds |= (unsigned int)kbd->lockstate << 8; spin_unlock_irqrestore(&led_lock, flags); + if (vt_switch) { + ledstate = ~leds; + vt_switch = false; + } + if (leds != ledstate) { kbd_propagate_led_state(ledstate, leds); ledstate = leds;