Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1706539pxb; Tue, 26 Oct 2021 14:18:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRAKni3VYNKor0SQSf5EfzJjQBHtesDjkIg32gIJLgpvhoMw3W+GGgSX/UsGQqwITfEXSg X-Received: by 2002:a05:6402:3587:: with SMTP id y7mr38883221edc.182.1635283103581; Tue, 26 Oct 2021 14:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635283103; cv=none; d=google.com; s=arc-20160816; b=qBxd2TmCBiQjAkNntJCK/reUVPmfP5cOcaQ1bBVr43M7AABawlw0mauMTG4JLoecJB lY4C2k56ukBmch6kpuJoji1iPbXRk21e33GNi6z4lbqLwZFV8ln4KQkAjrzcLD7G1aj6 nePaA1ZL6L/RL5Qfm5xwOLS3tt9DH1o6Z1HIz+VGhBY4xte1UCum34obrj5E37U9Xwcc fSw6gUM+MO9T1QdxfvoxDqIDXUKKxRpxBMK7vyfaZ3dPLjmb/oSN0rIvCqP5q7XGG+4s X8NZWYWiAhtsA0RIFewxiugvut0OTxcSKCeYr7IUN82PpwoLt+hDxF6ZVbwspGk16BZc JXvw== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=slCREXb4Szp7BH9fgmAYdoubjJI/xGkVyv/JOkRF0U0=; b=FEHP6u9/bGy3j7wYATZwYk09YH+0qQEb0asTlpv+77HLPViTxuPr7jgkvkkmIIw/sY VuI2jcKdUNoxBkx4AUmxyEgWMBwX9DWfkYUMEBGH2OcN4AQ9jikFBI/w5om7eLhEuESM wTLV+VTZJlZDHT7UFX9Eb7TrELEyheGoucI79WT/gTNYmdBMn4KQIbyVMZkrPHrGKqIL XDWZ7LTRhVGibvBvmkyhmV0x0DJT87IQSTIBiqLOxGvjHuuFUmAi7GgKvGPsRu3qXDh2 QjU78hrVUURck+JZB+wpm5iGPKuLVq8zK5JSiLL4d7I2TscNuncfihqvc7rvHup132sX fNxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="slyf/tjT"; 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 ca21si14617824edb.366.2021.10.26.14.17.59; Tue, 26 Oct 2021 14:18:23 -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="slyf/tjT"; 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 S237177AbhJZP7k (ORCPT + 99 others); Tue, 26 Oct 2021 11:59:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:54432 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237173AbhJZP7j (ORCPT ); Tue, 26 Oct 2021 11:59:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C0EF603E9; Tue, 26 Oct 2021 15:57:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635263835; bh=VYQq+e605O6Wf5bVvGMiK9obi4XNY/4uYmZtUWaw35E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=slyf/tjT23TqD1DhC4NxxzR41AbUMtYKfaj/oKJte4PJUcleNO/Sy1S/RKV3SVIkB 31fMZK1VswONfm7Q9+k7HfkNSxP+q6lkmEFb/0HT+UumUwjM1HkQF5hM+66cvOARR0 4UbWQqPUuV104cE47hp+FxGCuuI/DBI9tv7rBn+A= Date: Tue, 26 Oct 2021 17:57:12 +0200 From: Greg KH To: =?utf-8?B?5bi45buJ5b+X?= Cc: Andy Shevchenko , linux-kernel , "dmitry.torokhov" , jirislaby , 282827961 <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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 11:41:17PM +0800, 常廉志 wrote: > 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. > > I think it can be done like this: > static void kbd_update_ledstate(struct input_dev *dev) > { > ledstate = (test_bit(LED_SCROLL,dev->led) ?1 :0) > | (test_bit(LED_NUML,dev->led) ?2 :0) > | (test_bit(LED_CAPSL,dev->led) ?3 :0) > } Please write code for developers to read first, and compilers second. That ? : stuff is a mess, do not do that. thanks, greg k-h