* [PATCH 0/2] platform/x86: dell-laptop: rework kbd_led_level_{get,set}()
@ 2026-09-25 19:32 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 ` [PATCH 2/2] platform/x86: dell-laptop: Fix token-based keyboard brightness readback Yury Norov
0 siblings, 2 replies; 3+ messages in thread
From: Yury Norov @ 2026-09-25 19:32 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede,
Ilpo Järvinen, platform-driver-x86, open list
Cc: Yury Norov, Yury Norov
Simplify both functions by replacing open-coded loops and fix
brightness readback for sparse token masks.
Yury Norov (2):
platform/x86: dell-laptop: Use fns() in kbd_led_level_set()
platform/x86: dell-laptop: Fix token-based keyboard brightness
readback
drivers/platform/x86/dell/dell-laptop.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 1/2] platform/x86: dell-laptop: Use fns() in kbd_led_level_set()
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 ` Yury Norov
2026-09-25 19:32 ` [PATCH 2/2] platform/x86: dell-laptop: Fix token-based keyboard brightness readback Yury Norov
1 sibling, 0 replies; 3+ messages in thread
From: Yury Norov @ 2026-09-25 19:32 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede,
Ilpo Järvinen, platform-driver-x86, open list
Cc: Yury Norov, Yury Norov
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);
} else {
pr_warn("Keyboard brightness level control not supported\n");
ret = -ENXIO;
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 2/2] platform/x86: dell-laptop: Fix token-based keyboard brightness readback
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
1 sibling, 0 replies; 3+ messages in thread
From: Yury Norov @ 2026-09-25 19:32 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede,
Ilpo Järvinen, platform-driver-x86, open list
Cc: Yury Norov, Yury Norov
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-25 19:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] platform/x86: dell-laptop: Fix token-based keyboard brightness readback Yury Norov
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®