On 1/5/25 11:55, Adrian DC wrote:
> Tested with the following script and values
The patch description is supposed to explain the reason for the changes,
not test results. Test results are useful, but only appropriate after "---".
Guenter
> ---
>
> {
> # Access hwmon
> cd /sys/class/hwmon/hwmon1/
>
> # Set to 1 => 82
> echo -n ' [TEST] Set to 1 : '
> echo '1' >./fan1_max
> cat ./fan1_max
>
> # Set to 1234 => 1234
> echo -n ' [TEST] Set to 1234 : '
> echo '1234' >./fan1_max
> cat ./fan1_max
>
> # Reset to 0 => 0
> echo -n ' [TEST] Set to 0 : '
> echo '0' >./fan1_max
> cat ./fan1_max
> }
> ---
>
> Signed-off-by: Adrian DC <radian.dc@gmail.com>
> ---
> drivers/hwmon/adt7470.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
> index dbee6926fa05..712bc41b4a0d 100644
> --- a/drivers/hwmon/adt7470.c
> +++ b/drivers/hwmon/adt7470.c
> @@ -662,11 +662,15 @@ static int adt7470_fan_write(struct device *dev, u32 attr, int channel, long val
> struct adt7470_data *data = dev_get_drvdata(dev);
> int err;
>
> - if (val <= 0)
> + if (val < 0)
> return -EINVAL;
>
> - val = FAN_RPM_TO_PERIOD(val);
> - val = clamp_val(val, 1, 65534);
> + if (val) {
> + val = FAN_RPM_TO_PERIOD(val);
> + val = clamp_val(val, 1, 65534);
> + } else {
> + val = FAN_PERIOD_INVALID;
> + }
>
> switch (attr) {
> case hwmon_fan_min: