Channel index 0 is reserved for the internal diode and is set
unconditionally before parsing child nodes. If a child node specifies
reg = 0, it silently overwrites the internal diode label
Reject reg = 0 in child nodes and improve the error message to
include the invalid index value.
Signed-off-by: Ivy Lopez <skunkolee@gmail.com>
---
drivers/hwmon/emc1812.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/emc1812.c b/drivers/hwmon/emc1812.c
index 68575c27d090..143c3c07dbaa 100644
--- a/drivers/hwmon/emc1812.c
+++ b/drivers/hwmon/emc1812.c
@@ -809,9 +809,10 @@ static int emc1812_parse_fw_config(struct emc1812_data *data, struct device *dev
device_for_each_child_node_scoped(dev, child) {
ret = fwnode_property_read_u32(child, "reg", ®_nr);
- if (ret || reg_nr >= data->chip->phys_channels)
+ if (ret || reg_nr == 0 || reg_nr >= data->chip->phys_channels)
return dev_err_probe(dev, -EINVAL,
- "The index is higher then the chip supports\n");
+ "Invalid channel index %u\n",
+ reg_nr);
/* Mark channel as active */
set_bit(reg_nr, &data->active_ch_mask);
--
2.55.0