All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] hwmon: (dell-smm) Reject out-of-range pwm values
@ 2026-11-18  4:04 Rosen Penev
  2026-11-18  4:08 ` sashiko-bot
  2026-11-18  4:21 ` Guenter Roeck
  0 siblings, 2 replies; 3+ messages in thread
From: Rosen Penev @ 2026-11-18  4:04 UTC (permalink / raw)
  To: Pali Rohár, Guenter Roeck, Greg Kroah-Hartman, Arnd Bergmann
  Cc: linux-hwmon

dell_smm_write() scales the value written to pwmN with

	DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult)

before clamping the result to the valid fan states. The rounding adds
i8k_pwm_mult / 2 to val first, which overflows for values near
LONG_MAX and wraps to a large negative number. That is then clamped to
0, so writing a huge value turns the fan off instead of running it at
the highest speed. With the default fan_max of 2, writing any value
from LONG_MAX - 63 up to LONG_MAX selects fan state 0.

The pwm range is well defined, so return -EINVAL for values outside
0 to 255, as is the convention for pwm attributes.

Fixes: e7f5f275c62a ("i8k: Implement hwmon based fan speed control")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
Changes in v2:
- Return -EINVAL for values outside 0 to 255 instead of clamping them.
- Patch 2 of v1 was applied, so this is sent alone.
- v1: https://lore.kernel.org/linux-hwmon/3c36959a51788bbc5d08f364fe7d922b5c4d4d87.1794633179.git.rosenp@gmail.com/

Developed with the help of an AI coding assistant (Claude Opus 5.5),
as described in the v1 cover letter. I reviewed the change and I am
responsible for it.

Compile-tested only (W=1). The test machine's BIOS ignores manual pwm
writes, so the change could not be observed at runtime.

 drivers/hwmon/dell-smm-hwmon.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/hwmon/dell-smm-hwmon.c b/drivers/hwmon/dell-smm-hwmon.c
index 798d2fe9d8b2..301ce2bed6a6 100644
--- a/drivers/hwmon/dell-smm-hwmon.c
+++ b/drivers/hwmon/dell-smm-hwmon.c
@@ -1022,6 +1022,9 @@ static int dell_smm_write(struct device *dev, enum hwmon_sensor_types type, u32
 	case hwmon_pwm:
 		switch (attr) {
 		case hwmon_pwm_input:
+			if (val < 0 || val > 255)
+				return -EINVAL;
+
 			pwm = clamp_val(DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult), 0,
 					data->i8k_fan_max);
 

base-commit: 09560558c9eabd4e85b68a97fcd102f1186b4790
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] hwmon: (dell-smm) Reject out-of-range pwm values
  2026-11-18  4:04 [PATCH v2] hwmon: (dell-smm) Reject out-of-range pwm values Rosen Penev
@ 2026-11-18  4:08 ` sashiko-bot
  2026-11-18  4:21 ` Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-18  4:08 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-hwmon

> dell_smm_write() scales the value written to pwmN with
> 
> 	DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult)
> 
> before clamping the result to the valid fan states. The rounding adds
> i8k_pwm_mult / 2 to val first, which overflows for values near
> LONG_MAX and wraps to a large negative number. That is then clamped to
> 0, so writing a huge value turns the fan off instead of running it at
> the highest speed. With the default fan_max of 2, writing any value
> from LONG_MAX - 63 up to LONG_MAX selects fan state 0.
> 
> The pwm range is well defined, so return -EINVAL for values outside
> 0 to 255, as is the convention for pwm attributes.
> 
> Fixes: e7f5f275c62a ("i8k: Implement hwmon based fan speed control")
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118040417.19049-1-rosenp@gmail.com?part=1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] hwmon: (dell-smm) Reject out-of-range pwm values
  2026-11-18  4:04 [PATCH v2] hwmon: (dell-smm) Reject out-of-range pwm values Rosen Penev
  2026-11-18  4:08 ` sashiko-bot
@ 2026-11-18  4:21 ` Guenter Roeck
  1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-11-18  4:21 UTC (permalink / raw)
  To: Rosen Penev
  Cc: Pali Rohár, Greg Kroah-Hartman, Arnd Bergmann, linux-hwmon

On Tue, Nov 17, 2026 at 08:04:17PM -0800, Rosen Penev wrote:
> dell_smm_write() scales the value written to pwmN with
> 
> 	DIV_ROUND_CLOSEST(val, data->i8k_pwm_mult)
> 
> before clamping the result to the valid fan states. The rounding adds
> i8k_pwm_mult / 2 to val first, which overflows for values near
> LONG_MAX and wraps to a large negative number. That is then clamped to
> 0, so writing a huge value turns the fan off instead of running it at
> the highest speed. With the default fan_max of 2, writing any value
> from LONG_MAX - 63 up to LONG_MAX selects fan state 0.
> 
> The pwm range is well defined, so return -EINVAL for values outside
> 0 to 255, as is the convention for pwm attributes.
> 
> Fixes: e7f5f275c62a ("i8k: Implement hwmon based fan speed control")
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Applied.

Thanks,
Guenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-18  4:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18  4:04 [PATCH v2] hwmon: (dell-smm) Reject out-of-range pwm values Rosen Penev
2026-11-18  4:08 ` sashiko-bot
2026-11-18  4:21 ` Guenter Roeck

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.