hwmon: (f71882fg) prevent possible division by zero
authorNikita Zhandarovich <n.zhandarovich@fintech.ru>
Wed, 10 May 2023 14:35:37 +0000 (07:35 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Jul 2023 14:21:19 +0000 (16:21 +0200)
commit280e58d8b0e902556fa0c8dddc622ea9ea19af91
tree6edf13b33fb101f204be81d9b489e63a0059b096
parent08cc7cd2c2a29a2abf5bceb8f048c0734d3694ba
hwmon: (f71882fg) prevent possible division by zero

[ Upstream commit 0babf89c9cca7e074d6e59893e462e4886f481cc ]

In the unlikely event that something goes wrong with the device and
its registers, the fan_from_reg() function may return 0. This value
will cause a division-by-zero error in the show_pwm() function.

To prevent this, test the value of
fan_from_reg(data->fan_full_speed[nr]) against 0 before performing
the division. If the division-by-zero error is avoided, assign 0 to
the val variable.

Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.

Fixes: df9ec2dae094 ("hwmon: (f71882fg) Reorder symbols to get rid of a few forward declarations")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
Link: https://lore.kernel.org/r/20230510143537.145060-1-n.zhandarovich@fintech.ru
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hwmon/f71882fg.c