From: "Pali Rohár" <pali@kernel.org>
To: Yury Norov <ynorov@nvidia.com>
Cc: "Matthew Garrett" <mjg59@srcf.ucam.org>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
platform-driver-x86@vger.kernel.org,
"open list" <linux-kernel@vger.kernel.org>,
"Yury Norov" <yury.norov@gmail.com>
Subject: Re: [PATCH 1/2] platform/x86: dell-laptop: Use fns() in kbd_led_level_set()
Date: Wed, 18 Nov 2026 23:20:52 +0100 [thread overview]
Message-ID: <20261118222052.vshpmsfffyhl5hrl@pali> (raw)
In-Reply-To: <20260925193239.248779-2-ynorov@nvidia.com>
On Friday 25 September 2026 15:32:38 Yury Norov wrote:
> Replace the loop clearing lower set bits with fns() to select the
> supported token corresponding to the requested brightness. Preserve the
> zero return when the requested index is out of range.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> drivers/platform/x86/dell/dell-laptop.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
> index 89e85c7f7132..03d3bb70b0d1 100644
> --- a/drivers/platform/x86/dell/dell-laptop.c
> +++ b/drivers/platform/x86/dell/dell-laptop.c
> @@ -17,6 +17,7 @@
> #include <linux/init.h>
> #include <linux/platform_device.h>
> #include <linux/backlight.h>
> +#include <linux/bitops.h>
> #include <linux/err.h>
> #include <linux/dmi.h>
> #include <linux/io.h>
> @@ -2036,7 +2037,7 @@ static int kbd_led_level_set(struct led_classdev *led_cdev,
> enum led_brightness new_value = value;
> struct kbd_state state;
> struct kbd_state new_state;
> - u16 num;
> + unsigned int bit;
> int ret;
>
> mutex_lock(&kbd_led_mutex);
> @@ -2051,12 +2052,8 @@ static int kbd_led_level_set(struct led_classdev *led_cdev,
> goto out;
> ret = kbd_set_state_safe(&new_state, &state);
> } else if (kbd_get_valid_token_counts()) {
> - for (num = kbd_token_bits; num != 0 && value > 0; --value)
> - num &= num - 1; /* clear the first bit set */
> - if (num == 0)
> - ret = 0;
> - else
> - ret = kbd_set_token_bit(ffs(num) - 1);
> + bit = fns(kbd_token_bits, value);
> + ret = bit == BITS_PER_LONG ? 0 : kbd_set_token_bit(bit);
Maybe slightly better readable diff:
- for (num = kbd_token_bits; num != 0 && value > 0; --value)
- num &= num - 1; /* clear the first bit set */
+ bit = fns(kbd_token_bits, value);
- if (num == 0)
+ if (bit == BITS_PER_LONG)
ret = 0;
else
- ret = kbd_set_token_bit(ffs(num) - 1);
+ ret = kbd_set_token_bit(bit);
Otherwise looks good.
Reviewed-by: Pali Rohár <pali@kernel.org>
> } else {
> pr_warn("Keyboard brightness level control not supported\n");
> ret = -ENXIO;
> --
> 2.53.0
>
next prev parent reply other threads:[~2026-11-18 22:20 UTC|newest]
Thread overview: 6+ 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-11-18 22:20 ` Pali Rohár [this message]
2026-09-25 19:32 ` [PATCH 2/2] platform/x86: dell-laptop: Fix token-based keyboard brightness readback Yury Norov
2026-11-18 22:30 ` Pali Rohár
2026-11-18 21:17 ` [PATCH 0/2] platform/x86: dell-laptop: rework kbd_led_level_{get,set}() Yury Norov
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=20261118222052.vshpmsfffyhl5hrl@pali \
--to=pali@kernel.org \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mjg59@srcf.ucam.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=ynorov@nvidia.com \
--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®