LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v17] tty: Fix the keyboard led light display problem
@ 2021-11-26 11:27 lianzhi chang
  2021-11-26 15:31 ` Greg KH
  2021-11-26 15:51 ` Andy Shevchenko
  0 siblings, 2 replies; 3+ messages in thread
From: lianzhi chang @ 2021-11-26 11:27 UTC (permalink / raw)
  To: linux-kernel
  Cc: dmitry.torokhov, gregkh, jirislaby, andriy.shevchenko, 282827961,
	lianzhi chang

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 <changlianzhi@uniontech.com>
Suggested-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v17] tty: Fix the keyboard led light display problem
  2021-11-26 11:27 [PATCH v17] tty: Fix the keyboard led light display problem lianzhi chang
@ 2021-11-26 15:31 ` Greg KH
  2021-11-26 15:51 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2021-11-26 15:31 UTC (permalink / raw)
  To: lianzhi chang
  Cc: linux-kernel, dmitry.torokhov, jirislaby, andriy.shevchenko, 282827961

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v17] tty: Fix the keyboard led light display problem
  2021-11-26 11:27 [PATCH v17] tty: Fix the keyboard led light display problem lianzhi chang
  2021-11-26 15:31 ` Greg KH
@ 2021-11-26 15:51 ` Andy Shevchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2021-11-26 15:51 UTC (permalink / raw)
  To: lianzhi chang; +Cc: linux-kernel, dmitry.torokhov, gregkh, jirislaby, 282827961

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-26 15:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26 11:27 [PATCH v17] tty: Fix the keyboard led light display problem lianzhi chang
2021-11-26 15:31 ` Greg KH
2021-11-26 15:51 ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).