* [PATCH] hwmon: (emc2305) fix division by zero for a small tach reading
@ 2026-12-05 1:24 Shirong Zhao
2026-12-05 1:30 ` sashiko-bot
2026-12-05 16:27 ` Guenter Roeck
0 siblings, 2 replies; 3+ messages in thread
From: Shirong Zhao @ 2026-12-05 1:24 UTC (permalink / raw)
To: Guenter Roeck; +Cc: linux-hwmon, stable, Shirong Zhao
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.")
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
---
drivers/hwmon/emc2305.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/hwmon/emc2305.c b/drivers/hwmon/emc2305.c
index 434e70e..770b430 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;
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (emc2305) fix division by zero for a small tach reading
2026-12-05 1:24 [PATCH] hwmon: (emc2305) fix division by zero for a small tach reading Shirong Zhao
@ 2026-12-05 1:30 ` sashiko-bot
2026-12-05 16:27 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-05 1:30 UTC (permalink / raw)
To: Shirong Zhao; +Cc: linux-hwmon
> 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.")
> Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205012416.100-1-shxzhaosr@163.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: (emc2305) fix division by zero for a small tach reading
2026-12-05 1:24 [PATCH] hwmon: (emc2305) fix division by zero for a small tach reading Shirong Zhao
2026-12-05 1:30 ` sashiko-bot
@ 2026-12-05 16:27 ` Guenter Roeck
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-12-05 16:27 UTC (permalink / raw)
To: Shirong Zhao; +Cc: linux-hwmon, stable
On Sat, Dec 05, 2026 at 09:24:16AM +0800, Shirong Zhao wrote:
> 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.")
> Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-05 16:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 1:24 [PATCH] hwmon: (emc2305) fix division by zero for a small tach reading Shirong Zhao
2026-12-05 1:30 ` sashiko-bot
2026-12-05 16:27 ` Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.