* [PATCH v2 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling
@ 2026-11-21 0:09 Rosen Penev
2026-11-21 0:09 ` [PATCH v2 1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow Rosen Penev
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Rosen Penev @ 2026-11-21 0:09 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede,
Ilpo Järvinen, Gabriele Mazzotta, Darren Hart
Cc: platform-driver-x86, linux-kernel
Three fixes for dell-laptop: keyboard backlight timeouts that overflow
during unit conversion were silently accepted, an unread keyboard state
was used at init when the SMBIOS call failed, and the charge end
threshold was parsed as unsigned into an int.
These patches were developed with the help of an AI coding assistant
(Claude Opus 5.5): it reviewed the drivers, found the issues and drafted
the fixes and changelogs. I reviewed every change and I am responsible
for them.
All patches build cleanly with W=1.
Tested on a Dell Precision M4800 running v7.2.15, using the equivalent
backports built as out-of-tree modules:
- writing 4424214d / 18989323d to stop_timeout set 4m / 2m before
patch 1 and is rejected with -EINVAL after it; 5m still works
(v1 of patch 1; v2 is compile-tested only)
- charge_control_end_threshold rejects -1 and 101, accepts 85
The kbd_get_state() failure path of patch 2 was not triggered.
Changes in v2:
- patch 1: convert to a u64 seconds value instead of failing
check_mul_overflow() on the int, so the unit selection below works
on the full value; retitled (review feedback)
- patch 2: don't fail kbd_init_info() when kbd_get_state() fails;
fall back to level 0 / off mode so the existing code picks sane
defaults (review feedback)
v1: https://lore.kernel.org/r/cover.1794633179.git.rosenp@gmail.com
Rosen Penev (3):
platform/x86: dell-laptop: Fix keyboard backlight timeout overflow
platform/x86: dell-laptop: Don't use an unread keyboard state at init
platform/x86: dell-laptop: Parse the charge end threshold as an int
drivers/platform/x86/dell/dell-laptop.c | 47 +++++++++++++++----------
1 file changed, 29 insertions(+), 18 deletions(-)
--
2.56.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow
2026-11-21 0:09 [PATCH v2 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Rosen Penev
@ 2026-11-21 0:09 ` Rosen Penev
2026-11-21 0:09 ` [PATCH v2 2/3] platform/x86: dell-laptop: Don't use an unread keyboard state at init Rosen Penev
2026-11-21 0:09 ` [PATCH v2 3/3] platform/x86: dell-laptop: Parse the charge end threshold as an int Rosen Penev
2 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-11-21 0:09 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede,
Ilpo Järvinen, Gabriele Mazzotta, Darren Hart
Cc: platform-driver-x86, linux-kernel
kbd_led_timeout_store() converts a timeout that is too large for its
unit to seconds with plain int multiplication. A large enough value
wraps, and if the wrapped number happens to be a valid timeout it is
accepted. On a Precision M4800, writing "4424214d" (over 12000 years)
to stop_timeout sets the timeout to 4 minutes, and "18989323d" sets it
to 2 minutes.
Do the conversion and the following unit selection on a u64 seconds
value instead. With value <= INT_MAX this cannot overflow, so such
inputs are now rejected with -EINVAL like any other timeout that is too
large for the hardware, and nothing that was valid before is rejected.
Fixes: 02b2aaaa57ab ("platform: x86: dell-laptop: Add support for keyboard backlight")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: use a u64 seconds value instead of check_mul_overflow() on the int
drivers/platform/x86/dell/dell-laptop.c | 34 +++++++++++++++----------
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
index cad2bd06f28a..c1a51bf95c25 100644
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -25,6 +25,7 @@
#include <linux/sysfs.h>
#include <linux/acpi.h>
#include <linux/mm.h>
+#include <linux/math64.h>
#include <linux/i8042.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
@@ -1553,6 +1554,7 @@ static ssize_t kbd_led_timeout_store(struct device *dev,
struct kbd_state new_state;
struct kbd_state state;
bool convert;
+ u64 seconds;
int value;
int ret;
char ch;
@@ -1599,38 +1601,42 @@ static ssize_t kbd_led_timeout_store(struct device *dev,
convert = true;
if (convert) {
- /* Convert value from current units to seconds */
+ /*
+ * Convert value from current units to seconds. This is done in
+ * 64 bits so that it cannot overflow: value <= INT_MAX.
+ */
+ seconds = value;
switch (unit) {
case KBD_TIMEOUT_DAYS:
- value *= 24;
+ seconds *= 24;
fallthrough;
case KBD_TIMEOUT_HOURS:
- value *= 60;
+ seconds *= 60;
fallthrough;
case KBD_TIMEOUT_MINUTES:
- value *= 60;
- unit = KBD_TIMEOUT_SECONDS;
+ seconds *= 60;
}
if (quirks && quirks->needs_kbd_timeouts) {
for (i = 0; quirks->kbd_timeouts[i] != -1; i++) {
- if (value <= quirks->kbd_timeouts[i]) {
- value = quirks->kbd_timeouts[i];
+ if (seconds <= quirks->kbd_timeouts[i]) {
+ seconds = quirks->kbd_timeouts[i];
break;
}
}
}
- if (value <= kbd_info.seconds && kbd_info.seconds) {
+ if (seconds <= kbd_info.seconds && kbd_info.seconds) {
+ value = seconds;
unit = KBD_TIMEOUT_SECONDS;
- } else if (value / 60 <= kbd_info.minutes && kbd_info.minutes) {
- value /= 60;
+ } else if (div_u64(seconds, 60) <= kbd_info.minutes && kbd_info.minutes) {
+ value = div_u64(seconds, 60);
unit = KBD_TIMEOUT_MINUTES;
- } else if (value / (60 * 60) <= kbd_info.hours && kbd_info.hours) {
- value /= (60 * 60);
+ } else if (div_u64(seconds, 60 * 60) <= kbd_info.hours && kbd_info.hours) {
+ value = div_u64(seconds, 60 * 60);
unit = KBD_TIMEOUT_HOURS;
- } else if (value / (60 * 60 * 24) <= kbd_info.days && kbd_info.days) {
- value /= (60 * 60 * 24);
+ } else if (div_u64(seconds, 60 * 60 * 24) <= kbd_info.days && kbd_info.days) {
+ value = div_u64(seconds, 60 * 60 * 24);
unit = KBD_TIMEOUT_DAYS;
} else {
return -EINVAL;
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/3] platform/x86: dell-laptop: Don't use an unread keyboard state at init
2026-11-21 0:09 [PATCH v2 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Rosen Penev
2026-11-21 0:09 ` [PATCH v2 1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow Rosen Penev
@ 2026-11-21 0:09 ` Rosen Penev
2026-11-21 0:09 ` [PATCH v2 3/3] platform/x86: dell-laptop: Parse the charge end threshold as an int Rosen Penev
2 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-11-21 0:09 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede,
Ilpo Järvinen, Gabriele Mazzotta, Darren Hart
Cc: platform-driver-x86, linux-kernel
kbd_init_info() ignores the return value of kbd_get_state(). If the
call fails, the uninitialized state on the stack is used to set
kbd_previous_level and kbd_previous_mode_bit, which are later sent to
the BIOS when triggers are enabled or the backlight is turned back on.
kbd_get_info() has already succeeded at that point, so a failure here
may well be transient and is not a reason to give up on the keyboard
backlight. Start from level 0 and the off mode instead: the code below
then picks level 1 and the first supported mode, as it already does
when the backlight is off at boot.
Fixes: 02b2aaaa57ab ("platform: x86: dell-laptop: Add support for keyboard backlight")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v2: fall back to level 0 / off mode instead of returning the error
drivers/platform/x86/dell/dell-laptop.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
index c1a51bf95c25..eca348497ac3 100644
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -1455,7 +1455,7 @@ static inline int kbd_init_info(void)
dell_smbios_find_token(KBD_LED_AC_TOKEN))
kbd_timeout_ac_supported = true;
- kbd_get_state(&state);
+ ret = kbd_get_state(&state);
/* NOTE: timeout value is stored in 6 bits so max value is 63 */
if (kbd_info.seconds > 63)
@@ -1472,8 +1472,13 @@ static inline int kbd_init_info(void)
*/
kbd_info.modes &= ~BIT(KBD_MODE_BIT_ON);
- kbd_previous_level = kbd_get_level(&state);
- kbd_previous_mode_bit = state.mode_bit;
+ if (ret == 0) {
+ kbd_previous_level = kbd_get_level(&state);
+ kbd_previous_mode_bit = state.mode_bit;
+ } else {
+ kbd_previous_level = 0;
+ kbd_previous_mode_bit = KBD_MODE_BIT_OFF;
+ }
if (kbd_previous_level == 0 && kbd_get_max_level() != 0)
kbd_previous_level = 1;
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 3/3] platform/x86: dell-laptop: Parse the charge end threshold as an int
2026-11-21 0:09 [PATCH v2 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Rosen Penev
2026-11-21 0:09 ` [PATCH v2 1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow Rosen Penev
2026-11-21 0:09 ` [PATCH v2 2/3] platform/x86: dell-laptop: Don't use an unread keyboard state at init Rosen Penev
@ 2026-11-21 0:09 ` Rosen Penev
2 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-11-21 0:09 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede,
Ilpo Järvinen, Gabriele Mazzotta, Darren Hart
Cc: platform-driver-x86, linux-kernel
charge_control_end_threshold_store() passes a pointer to an int to
kstrtouint(), which only builds because the kernel disables
-Wpointer-sign, and makes the following "end < 0" check dead code.
Use kstrtoint() like charge_control_start_threshold_store(). Values
outside 0 to 100 are rejected either way.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/platform/x86/dell/dell-laptop.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
index eca348497ac3..c512267be4c4 100644
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -2382,7 +2382,7 @@ static ssize_t charge_control_end_threshold_store(struct device *dev,
{
int ret, end;
- ret = kstrtouint(buf, 10, &end);
+ ret = kstrtoint(buf, 10, &end);
if (ret)
return ret;
if (end < 0 || end > 100)
--
2.56.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-21 0:09 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 0:09 [PATCH v2 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Rosen Penev
2026-11-21 0:09 ` [PATCH v2 1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow Rosen Penev
2026-11-21 0:09 ` [PATCH v2 2/3] platform/x86: dell-laptop: Don't use an unread keyboard state at init Rosen Penev
2026-11-21 0:09 ` [PATCH v2 3/3] platform/x86: dell-laptop: Parse the charge end threshold as an int Rosen Penev
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.