Re: [PATCH v6 1/3] hwmon: emc2305: Validate fan channel index

From: Guenter Roeck

Date: Fri Apr 10 2026 - 12:09:38 EST


On 4/2/26 05:25, florin.leotescu@xxxxxxxxxxx wrote:
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)

Please address Sashiko's concerns regarding channel index validation.
It seems valid to me. Feel free to ignore the other comments.

https://sashiko.dev/#/patchset/20260402122514.1811737-1-florin.leotescu%40oss.nxp.com

Thanks,
Guenter