Commit 094bd75eae81 for kernel
commit 094bd75eae81cee2aee6fdfc947234c02929fd23
Author: Shirong Zhao <shxzhaosr@163.com>
Date: Sat Dec 5 09:24:16 2026 +0800
hwmon: (emc2305) fix division by zero for a small tach reading
emc2305_show_fan() guards the raw 16-bit tach register value with
`if (ret <= 0)`, then shifts it right by EMC2305_TACH_REGS_UNUSE_BITS (3)
before dividing:
ret = ret >> EMC2305_TACH_REGS_UNUSE_BITS;
ret = EMC2305_RPM_FACTOR / ret;
A tach register value of 1..7 survives the first check but becomes 0
after the shift, so the division is a divide by zero. The register value
comes from the fan controller (the driver never writes it); reading the
read-only fan1_input attribute of a faulty or emulated controller that
reports 1..7 therefore crashes the kernel. Userspace only triggers the
read; the zero divisor is device-provided.
Re-check for zero after the shift.
Fixes: 0d8400c5a2ce ("hwmon: (emc2305) add support for EMC2301/2/3/5 RPM-based PWM Fan Speed Controller.")
Cc: stable@vger.kernel.org
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
Link: https://patch.msgid.link/20261205012416.100-1-shxzhaosr@163.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
diff --git a/drivers/hwmon/emc2305.c b/drivers/hwmon/emc2305.c
index 434e70e76f5f..770b43048408 100644
--- a/drivers/hwmon/emc2305.c
+++ b/drivers/hwmon/emc2305.c
@@ -270,6 +270,8 @@ static int emc2305_show_fan(struct device *dev, int channel)
return ret;
ret = ret >> EMC2305_TACH_REGS_UNUSE_BITS;
+ if (ret == 0)
+ return 0;
ret = EMC2305_RPM_FACTOR / ret;
if (ret <= EMC2305_TACH_RANGE_MIN)
return 0;