Skip to content

Commit 8aebbbb

Browse files
almostivangroeck
authored andcommitted
hwmon: (nct7904) Correct divide by 0
We hit a kernel panic due to a divide by 0 in nct7904_read_fan() for the hwmon_fan_min case. Extend the check to hwmon_fan_input case as well for safety. [ 1656.545650] divide error: 0000 [#1] SMP PTI [ 1656.545779] CPU: 12 PID: 18010 Comm: sensors Not tainted 5.4.47 #1 [ 1656.546065] RIP: 0010:nct7904_read+0x1e9/0x510 [nct7904] ... [ 1656.546549] RAX: 0000000000149970 RBX: ffffbd6b86bcbe08 RCX: 0000000000000000 ... [ 1656.547548] Call Trace: [ 1656.547665] hwmon_attr_show+0x32/0xd0 [hwmon] [ 1656.547783] dev_attr_show+0x18/0x50 [ 1656.547898] sysfs_kf_seq_show+0x99/0x120 [ 1656.548013] seq_read+0xd8/0x3e0 [ 1656.548127] vfs_read+0x89/0x130 [ 1656.548234] ksys_read+0x7d/0xb0 [ 1656.548342] do_syscall_64+0x48/0x110 [ 1656.548451] entry_SYSCALL_64_after_hwframe+0x44/0xa9 Fixes: d65a510 ("hwmon: (nct7904) Convert to use new hwmon registration API") Signed-off-by: Jason Baron <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 51fb91e commit 8aebbbb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/hwmon/nct7904.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
231231
if (ret < 0)
232232
return ret;
233233
cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f);
234-
if (cnt == 0x1fff)
234+
if (cnt == 0 || cnt == 0x1fff)
235235
rpm = 0;
236236
else
237237
rpm = 1350000 / cnt;
@@ -243,7 +243,7 @@ static int nct7904_read_fan(struct device *dev, u32 attr, int channel,
243243
if (ret < 0)
244244
return ret;
245245
cnt = ((ret & 0xff00) >> 3) | (ret & 0x1f);
246-
if (cnt == 0x1fff)
246+
if (cnt == 0 || cnt == 0x1fff)
247247
rpm = 0;
248248
else
249249
rpm = 1350000 / cnt;

0 commit comments

Comments
 (0)