[PATCH v6 1/3] hwmon: emc2305: Validate fan channel index
From: florin . leotescu
Date: Thu Apr 02 2026 - 08:11:43 EST
From: Florin Leotescu <florin.leotescu@xxxxxxx>
The fan channel index is used to access per-channel data structures.
Validate the index agains the number of available channels
before use to prevent out-of-bounds access if an invalid
value is provided.
Signed-off-by: Florin Leotescu <florin.leotescu@xxxxxxx>
---
drivers/hwmon/emc2305.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/hwmon/emc2305.c b/drivers/hwmon/emc2305.c
index 64b213e1451e..0b42b82c8e22 100644
--- a/drivers/hwmon/emc2305.c
+++ b/drivers/hwmon/emc2305.c
@@ -548,6 +548,12 @@ static int emc2305_of_parse_pwm_child(struct device *dev,
return ret;
}
+ if (ch >= data->pwm_num) {
+ dev_err(dev, "invalid reg %u for node %pOF (valid range 0-%u)\n", ch, child,
+ data->pwm_num - 1);
+ return -EINVAL;
+ }
+
ret = of_parse_phandle_with_args(child, "pwms", "#pwm-cells", 0, &args);
if (ret)
--
2.34.1