mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-20 01:20:54 +00:00
hwmon: (adt7470) Prevent divide by zero in adt7470_fan_write()
[ Upstream commitc1ec0cabc3
] 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:fc958a61ff
("hwmon: (adt7470) Convert to devm_hwmon_device_register_with_info API") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
774a6ef814
commit
b9dc12e481
1 changed files with 3 additions and 0 deletions
|
@ -662,6 +662,9 @@ 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)
|
||||
return -EINVAL;
|
||||
|
||||
val = FAN_RPM_TO_PERIOD(val);
|
||||
val = clamp_val(val, 1, 65534);
|
||||
|
||||
|
|
Loading…
Reference in a new issue