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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 1 Feb 2022 16:27:12 +0000 (17:27 +0100)
commitb9dc12e481c0e20ee762fb7a3668c08acf8b2e7c
tree442b88e820cfb6f44054c6981669e6158f015bab
parent774a6ef81458b86d0034dc663c9e5622879f81ea
hwmon: (adt7470) Prevent divide by zero in adt7470_fan_write()

[ Upstream commit c1ec0cabc36718efc7fe8b4157d41b82d08ec1d2 ]

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: fc958a61ff6d ("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>
drivers/hwmon/adt7470.c