Skip to content

Commit b349988

Browse files
Wer-Wolfgroeck
authored andcommitted
hwmon: (dell-smm) Move clamping of fan speed out of i8k_set_fan()
Currently i8k_set_fan() clamps the fan speed before performing the SMM call to ensure that the speed is not negative and not greater than i8k_fan_max. This however is mostly unnecessary as the hwmon and thermal interfaces alread ensure this. Only the legacy ioctl interface does not ensure that the fan speed passed to i8k_set_fan() does meet the above criteria. Move the clamping out of i8k_set_fan() and into the legacy ioctl handler to prepare for future changes. Signed-off-by: Armin Wolf <W_Armin@gmx.de> Link: https://lore.kernel.org/r/20250917181036.10972-3-W_Armin@gmx.de Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent ddb61e7 commit b349988

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/hwmon/dell-smm-hwmon.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/init.h>
2525
#include <linux/kconfig.h>
2626
#include <linux/kernel.h>
27+
#include <linux/minmax.h>
2728
#include <linux/module.h>
2829
#include <linux/mutex.h>
2930
#include <linux/platform_device.h>
@@ -446,7 +447,6 @@ static int i8k_set_fan(const struct dell_smm_data *data, u8 fan, int speed)
446447
if (disallow_fan_support)
447448
return -EINVAL;
448449

449-
speed = (speed < 0) ? 0 : ((speed > data->i8k_fan_max) ? data->i8k_fan_max : speed);
450450
regs.ebx = fan | (speed << 8);
451451

452452
return dell_smm_call(data->ops, &regs);
@@ -637,6 +637,8 @@ static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
637637
if (copy_from_user(&speed, argp + 1, sizeof(int)))
638638
return -EFAULT;
639639

640+
speed = clamp_val(speed, 0, data->i8k_fan_max);
641+
640642
mutex_lock(&data->i8k_mutex);
641643
err = i8k_set_fan(data, val, speed);
642644
if (err < 0)

0 commit comments

Comments
 (0)