mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yury Norov <ynorov@nvidia.com>
To: "Matthew Garrett" <mjg59@srcf.ucam.org>,
	"Pali Rohár" <pali@kernel.org>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org (open list)
Cc: Yury Norov <ynorov@nvidia.com>, Yury Norov <yury.norov@gmail.com>
Subject: [PATCH 2/2] platform/x86: dell-laptop: Fix token-based keyboard brightness readback
Date: Fri, 25 Sep 2026 15:32:39 -0400	[thread overview]
Message-ID: <20260925193239.248779-3-ynorov@nvidia.com> (raw)
In-Reply-To: <20260925193239.248779-1-ynorov@nvidia.com>

kbd_get_first_active_token_bit() returns an index into kbd_tokens, while
LED brightness is an ordinal among the supported tokens. These differ
when supported token bits are not consecutive starting at bit 0.

Count the supported token bits below the active token with hweight16()
to recover its zero-based brightness ordinal.

Return zero directly when ret == 0: token bit 0 has no supported tokens
below it, so its brightness ordinal is zero.

Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
 drivers/platform/x86/dell/dell-laptop.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
index 03d3bb70b0d1..55fd48222e5e 100644
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -2003,7 +2003,6 @@ static const struct attribute_group *kbd_led_groups[] = {
 static enum led_brightness kbd_led_level_get(struct led_classdev *led_cdev)
 {
 	int ret;
-	u16 num;
 	struct kbd_state state;
 
 	if (kbd_get_max_level()) {
@@ -2018,13 +2017,10 @@ static enum led_brightness kbd_led_level_get(struct led_classdev *led_cdev)
 
 	if (kbd_get_valid_token_counts()) {
 		ret = kbd_get_first_active_token_bit();
-		if (ret < 0)
-			return 0;
-		for (num = kbd_token_bits; num != 0 && ret > 0; --ret)
-			num &= num - 1; /* clear the first bit set */
-		if (num == 0)
+		if (ret <= 0)
 			return 0;
-		return ffs(num) - 1;
+		/* Brightness is the active token's rank among supported tokens. */
+		return hweight16(kbd_token_bits & GENMASK(ret - 1, 0));
 	}
 
 	pr_warn("Keyboard brightness level control not supported\n");
-- 
2.53.0

      parent reply	other threads:[~2026-09-25 19:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 19:32 [PATCH 0/2] platform/x86: dell-laptop: rework kbd_led_level_{get,set}() Yury Norov
2026-09-25 19:32 ` [PATCH 1/2] platform/x86: dell-laptop: Use fns() in kbd_led_level_set() Yury Norov
2026-09-25 19:32 ` Yury Norov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260925193239.248779-3-ynorov@nvidia.com \
    --to=ynorov@nvidia.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mjg59@srcf.ucam.org \
    --cc=pali@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®