Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1663298pxb; Tue, 26 Oct 2021 13:19:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFuldk1hNxDgTFgKOXA8r8fNnVI7QLRtq/ErrwTm8Ok57EgkJMEBbNPdFyr7au8ub8mg+j X-Received: by 2002:a17:902:ec88:b0:141:60ff:fb91 with SMTP id x8-20020a170902ec8800b0014160fffb91mr2998486plg.81.1635279574166; Tue, 26 Oct 2021 13:19:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635279574; cv=none; d=google.com; s=arc-20160816; b=L3WfUg2B1ZVtaJfDRTRIdfmeZVhCyDcDZ3kaL4eyBUOx0KXUGv7maLSfB8Uioi4wZO GiSd8w70mD6EL5cmlsITlnzOx1e4I5JLturhzoK5Xg+ovSj3BptUDhFRwXHTzjC5HDRA WHvhQgVkVof+CVFM5LUpul784/V6pM8SHYhMkcK3KJ2TOauG876AtZiVKDWbyrem2x0x eeriLsAWvxb7YUvpSMMgjR5c1DDisD4zwLirzq/34mM2P0nqKRDnbMbjkIWxdE3PkSaX ZEr8kquhECg2mvSGP7+wroUj0Qv015nqYqG4fDt54I7xx5MMOKQ0AmGPsUlp0WiXEgoS ieLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EWzgddyaUrfKUHdsWrYQOX3l/9sOtYOaa7aNefQAu7Y=; b=xyvZluwlbhZP8np1HiCUDbNOGtqy+NdLSCeO2UGRuacdXBkuLZFIRg6L7RiuFNX/YK BBeHNTQt0Vk2PvwAH9hsN/3xNu1cmfzw1mracV/Ut22NCzF7cRLPwjUg+gYG0Whkh9uU er8eUnUAezEa3t98Sub7MPIX0uPPPVMCPAEAQG2Kd0FSCAlv9QkexYYo8IBbqYpRgMJL YkGbmbyG6q69KNX6QsDzDz5UVJ7j4H8HjqZ/72hAmRio7qsZupS0uWHbH7Au6yZ9M74R L9gWNWPVZHE3qd0nJrSVB+G5XOCNVorCL+Xg/HjfWgUpz++OtpU6EEkgG13ThoZPRhqy MFRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lhifqTNU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a5si29534851pgw.365.2021.10.26.13.19.21; Tue, 26 Oct 2021 13:19:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lhifqTNU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235327AbhJZOz7 (ORCPT + 99 others); Tue, 26 Oct 2021 10:55:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:54966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbhJZOz6 (ORCPT ); Tue, 26 Oct 2021 10:55:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 25F3B60E73; Tue, 26 Oct 2021 14:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635260014; bh=XWVXck4BTc3O6D5MfPddpqYC5tdKxec60b3+5QEzROQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lhifqTNUtFD8nrTJq+H5e70MsMniLlZ/R4K8HpU02g//8sjFRZVkrqLdWhsjxJRLc nfCvXMMz6UkRZZXDGk6CBz9lmbKQieG7B3yY1Ku7OEt68nPb17IWjRF/GAHtmJsRDW E9N/mDX2e0Lo9UfJsFYm3hQvg3CUfu9bbJcO+0bM= Date: Tue, 26 Oct 2021 16:53:32 +0200 From: Greg KH To: Andy Shevchenko Cc: lianzhi chang , linux-kernel@vger.kernel.org, dmitry.torokhov@gmail.com, jirislaby@kernel.org, 282827961@qq.com Subject: Re: [PATCH v7] tty: Fix the keyboard led light display problem Message-ID: References: <20211026024032.15897-1-changlianzhi@uniontech.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 05:23:35PM +0300, Andy Shevchenko wrote: > On Tue, Oct 26, 2021 at 10:40:32AM +0800, lianzhi chang wrote: > > Switching from the desktop environment to the tty environment, > > the state of the keyboard led lights and the state of the keyboard > > lock are inconsistent. This is because the attribute kb->kbdmode > > of the tty bound in the desktop environment (xorg) is set to > > Xorg > > I think I already pointed that out. > > > VC_OFF, which causes the ledstate and kb->ledflagstate > > values of the bound tty to always be 0, which causes the switch > > from the desktop When to the tty environment, the LED light > > status is inconsistent with the keyboard lock status. > > ... > > > +static void kbd_update_ledstate(struct input_dev *dev) > > +{ > > + if (!!test_bit(LED_NUML, dev->led) != > > + !!(ledstate & BIT(VC_NUMLOCK))) > > + ledstate ^= BIT(VC_NUMLOCK); > > + if (!!test_bit(LED_CAPSL, dev->led) != > > + !!(ledstate & BIT(VC_CAPSLOCK))) > > + ledstate ^= BIT(VC_CAPSLOCK); > > + if (!!test_bit(LED_SCROLLL, dev->led) != > > + !!(ledstate & BIT(VC_SCROLLOCK))) > > + ledstate ^= BIT(VC_SCROLLOCK); > > This looks ugly. Agreed, we also have the vc_kbd_led() and friend functions that seem to be ignored here :( > > Since LED_* are part of uAPI and VC_* are not, perhaps > makes sense to modify kbd_kern.h and optimize above > (disclaimer: compile tested only, no locking or other > synchronization have been checked / reviewed / etc): > > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c > index c7fbbcdcc346..2b04eaa5c6fd 100644 > --- a/drivers/tty/vt/keyboard.c > +++ b/drivers/tty/vt/keyboard.c > @@ -49,6 +49,11 @@ > > #include > > +/* We rely on these in kbd_update_ledstate() */ > +static_assert(VC_NUMLOCK == LED_NUML); > +static_assert(VC_CAPSLOCK == LED_CAPSL); > +static_assert(VC_SCROLLOCK == LED_SCROLLL); This makes more sense, these should be in sync. > + > /* > * Exported functions/variables > */ > @@ -1130,6 +1135,15 @@ static void kbd_init_leds(void) > > #endif > > +static void kbd_update_ledstate(struct input_dev *dev) > +{ > + unsigned long leds = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL); > + unsigned long newstate = *dev->led; > + > + newstate ^= ledstate; > + ledstate ^= newstate & leds; You should document the bit twiddling hack you are doing here just to make it easier to understand :) Also, ledstate is an unsigned int, not unsigned long, perhaps make them all u32 for now to make it obvious they are the same? Or u64? thanks, greg k-h