* [PATCH v4 1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow
2026-11-27 2:53 [PATCH v4 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Rosen Penev
@ 2026-11-27 2:53 ` Rosen Penev
2026-11-27 2:53 ` [PATCH v4 2/3] platform/x86: dell-laptop: Don't use an unread keyboard state at init Rosen Penev
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Rosen Penev @ 2026-11-27 2:53 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede,
Ilpo Järvinen, Darren Hart, Gabriele Mazzotta
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: 6cff8d60aa0a ("platform: x86: dell-laptop: Add support for keyboard backlight")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v4: Fixes: 6cff8d60aa0a instead of the reverted 02b2aaaa57ab
v3: unchanged
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] 5+ messages in thread* [PATCH v4 2/3] platform/x86: dell-laptop: Don't use an unread keyboard state at init
2026-11-27 2:53 [PATCH v4 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Rosen Penev
2026-11-27 2:53 ` [PATCH v4 1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow Rosen Penev
@ 2026-11-27 2:53 ` Rosen Penev
2026-11-27 2:53 ` [PATCH v4 3/3] platform/x86: dell-laptop: Make the charge end threshold unsigned Rosen Penev
2026-12-01 14:50 ` [PATCH v4 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Ilpo Järvinen
3 siblings, 0 replies; 5+ messages in thread
From: Rosen Penev @ 2026-11-27 2:53 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede,
Ilpo Järvinen, Darren Hart, Gabriele Mazzotta
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: 6cff8d60aa0a ("platform: x86: dell-laptop: Add support for keyboard backlight")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v4: Fixes: 6cff8d60aa0a instead of the reverted 02b2aaaa57ab
v3: unchanged
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] 5+ messages in thread* [PATCH v4 3/3] platform/x86: dell-laptop: Make the charge end threshold unsigned
2026-11-27 2:53 [PATCH v4 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Rosen Penev
2026-11-27 2:53 ` [PATCH v4 1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow Rosen Penev
2026-11-27 2:53 ` [PATCH v4 2/3] platform/x86: dell-laptop: Don't use an unread keyboard state at init Rosen Penev
@ 2026-11-27 2:53 ` Rosen Penev
2026-12-01 14:50 ` [PATCH v4 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Ilpo Järvinen
3 siblings, 0 replies; 5+ messages in thread
From: Rosen Penev @ 2026-11-27 2:53 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede,
Ilpo Järvinen, Darren Hart, Gabriele Mazzotta
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.
Declare end as unsigned int to match kstrtouint() and drop the dead
check. kstrtouint() already rejects negative input, so the accepted
range is unchanged.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
v4: unchanged
v3: make end unsigned int and drop the dead check instead of switching
to kstrtoint(); retitled (review feedback)
v2: unchanged
drivers/platform/x86/dell/dell-laptop.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/dell/dell-laptop.c b/drivers/platform/x86/dell/dell-laptop.c
index eca348497ac3..1e2867f182c8 100644
--- a/drivers/platform/x86/dell/dell-laptop.c
+++ b/drivers/platform/x86/dell/dell-laptop.c
@@ -2380,12 +2380,13 @@ static ssize_t charge_control_end_threshold_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
- int ret, end;
+ unsigned int end;
+ int ret;
ret = kstrtouint(buf, 10, &end);
if (ret)
return ret;
- if (end < 0 || end > 100)
+ if (end > 100)
return -EINVAL;
ret = dell_battery_set_custom_charge_end(end);
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v4 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling
2026-11-27 2:53 [PATCH v4 0/3] platform/x86: dell-laptop: Fix keyboard backlight and charge threshold handling Rosen Penev
` (2 preceding siblings ...)
2026-11-27 2:53 ` [PATCH v4 3/3] platform/x86: dell-laptop: Make the charge end threshold unsigned Rosen Penev
@ 2026-12-01 14:50 ` Ilpo Järvinen
3 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2026-12-01 14:50 UTC (permalink / raw)
To: Matthew Garrett, Pali Rohár, Hans de Goede, Darren Hart,
Gabriele Mazzotta, Rosen Penev
Cc: platform-driver-x86, linux-kernel
On Thu, 26 Nov 2026 18:53:35 -0800, Rosen Penev wrote:
> 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 with kstrtouint() 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.
>
> [...]
Thank you for your contribution, it has been applied to my local
review-ilpo-next branch. Note it will show up in the public
platform-drivers-x86/review-ilpo-next branch only once I've pushed my
local branch there, which might take a while.
FYI [if applicable to your patch], as per Linus' policy change, also
fixes are mostly routed through for-next unless the fix is for a
commit introduced in the most recent cycle or is clearly a regression
fix.
The list of commits applied:
[1/3] platform/x86: dell-laptop: Fix keyboard backlight timeout overflow
commit: 61d5a22f76c28a2fd26df9dee2ec726ed79e9946
[2/3] platform/x86: dell-laptop: Don't use an unread keyboard state at init
commit: aa730072d1bedd6766136a9b1f2600e2d0441ca5
[3/3] platform/x86: dell-laptop: Make the charge end threshold unsigned
commit: 268f771ee350a4e758b2eaaa558e51282b7c07ee
--
i.
^ permalink raw reply [flat|nested] 5+ messages in thread