[PATCH] hwmon: emc1812: reject channel index 0 in device tree config

Ivy Lopez posted 1 patch 1 week, 2 days ago
drivers/hwmon/emc1812.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
[PATCH] hwmon: emc1812: reject channel index 0 in device tree config
Posted by Ivy Lopez 1 week, 2 days ago
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", &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
Re: [PATCH] hwmon: emc1812: reject channel index 0 in device tree config
Posted by Guenter Roeck 1 week, 2 days ago
On 7/15/26 17:25, Ivy Lopez wrote:
> 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
> 

The label string "internal_diode" is completely meaningless.
If anything, it should be dropped. I see it as a good thing,
not as a bug, that it can be overwritten.

NACK.

Guenter