Skip to content

Commit c1ec0ca

Browse files
Dan Carpentergroeck
authored andcommitted
hwmon: (adt7470) Prevent divide by zero in adt7470_fan_write()
The "val" variable is controlled by the user and comes from hwmon_attr_store(). The FAN_RPM_TO_PERIOD() macro divides by "val" so a zero will crash the system. Check for that and return -EINVAL. Negatives are also invalid so return -EINVAL for those too. Fixes: fc958a6 ("hwmon: (adt7470) Convert to devm_hwmon_device_register_with_info API") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent f1e75e0 commit c1ec0ca

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/hwmon/adt7470.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ static int adt7470_fan_write(struct device *dev, u32 attr, int channel, long val
662662
struct adt7470_data *data = dev_get_drvdata(dev);
663663
int err;
664664

665+
if (val <= 0)
666+
return -EINVAL;
667+
665668
val = FAN_RPM_TO_PERIOD(val);
666669
val = clamp_val(val, 1, 65534);
667670

0 commit comments

Comments
 (0)