]> git.baikalelectronics.ru Git - kernel.git/commit
hwmon: (adt7470) Prevent divide by zero in adt7470_fan_write()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 21 Jan 2022 11:55:43 +0000 (14:55 +0300)
committerGuenter Roeck <linux@roeck-us.net>
Mon, 24 Jan 2022 02:21:27 +0000 (18:21 -0800)
commit4715f6cfbeee8a42d8889dfd00376a76e040255f
treeb5d6310739692d7f6154ac877405c3a434ff79d2
parentccf11cbc01b4ad562dc5f7f1fdd33bb38def18b4
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: 806bf47b7340 ("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>
drivers/hwmon/adt7470.c