2021-11-26 11:29:49

by lianzhi chang

[permalink] [raw]
Subject: [PATCH v17] tty: Fix the keyboard led light display problem

By judging the value of kb->kbdmode to determine whether it is necessary
to forcibly set the led state of the keyboard when switching between
different ttys. Solve the problem of the inconsistency between the
keyboard led status and the keyboard lock status in some scenarios,
such as the scenario where the desktop and tty switch mutually.

Signed-off-by: lianzhi chang <[email protected]>
Suggested-by: Dmitry Torokhov <[email protected]>
---
v17: Modify the description information.

drivers/tty/vt/keyboard.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index c7fbbcdcc346..e60ac9f39d6c 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
@@ -412,9 +413,21 @@ static void do_compute_shiftstate(void)
/* We still have to export this method to vt.c */
void vt_set_leds_compute_shiftstate(void)
{
+ struct kbd_struct *kb;
unsigned long flags;

- set_leds();
+ /*
+ * When switching VT, according to the value of kb->kbdmode,
+ * judge whether it is necessary to force the keyboard light
+ * state to be issued.
+ */
+ kb = kbd_table + fg_console;
+ if (kb->kbdmode == VC_RAW ||
+ kb->kbdmode == VC_MEDIUMRAW ||
+ kb->kbdmode == VC_OFF) {
+ vt_switch = true;
+ set_leds();
+ }

spin_lock_irqsave(&kbd_event_lock, flags);
do_compute_shiftstate();
@@ -1255,6 +1268,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;
--
2.20.1





2021-11-26 15:40:28

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH v17] tty: Fix the keyboard led light display problem

On Fri, Nov 26, 2021 at 07:27:27PM +0800, lianzhi chang wrote:
> By judging the value of kb->kbdmode to determine whether it is necessary
> to forcibly set the led state of the keyboard when switching between
> different ttys. Solve the problem of the inconsistency between the
> keyboard led status and the keyboard lock status in some scenarios,
> such as the scenario where the desktop and tty switch mutually.

No, the original text was all good, it was just not readable.

Try putting some paragraph breaks in it. You had numbered lists, so put
those so that they are readable.

Just some basic formatting to make it able to be understood. Do not
delete the whole thing :(

greg k-h

2021-11-26 15:54:32

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v17] tty: Fix the keyboard led light display problem

On Fri, Nov 26, 2021 at 07:27:27PM +0800, lianzhi chang wrote:
> By judging the value of kb->kbdmode to determine whether it is necessary
> to forcibly set the led state of the keyboard when switching between
> different ttys. Solve the problem of the inconsistency between the
> keyboard led status and the keyboard lock status in some scenarios,
> such as the scenario where the desktop and tty switch mutually.

Since it will be a next version, see one comment below you may address as well.

...

> + /*
> + * When switching VT, according to the value of kb->kbdmode,
> + * judge whether it is necessary to force the keyboard light
> + * state to be issued.
> + */
> + kb = kbd_table + fg_console;
> + if (kb->kbdmode == VC_RAW ||
> + kb->kbdmode == VC_MEDIUMRAW ||
> + kb->kbdmode == VC_OFF) {

checkpatch usually complains on indentation above.

Can you simply do it like

if (kb->kbdmode == VC_RAW ||
kb->kbdmode == VC_MEDIUMRAW ||
kb->kbdmode == VC_OFF) {

?

Alternatively it might be converted to a switch-case, but it takes more LOCs.

switch {
case VC_RAW:
case VC_MEDIUMRAW :
case VC_OFF:
vt_switch = true;
set_leds();
break;
default:
break;
}

> + vt_switch = true;
> + set_leds();
> + }

--
With Best Regards,
Andy Shevchenko