Skip to contentSkip to conversation

hwmon: emc1812: reject channel index 0 in device tree config

PATCH NAK Ivy Lopez 3 participants 3 messages Jul 16

Subsystems (2)
lore
Share & tools
lore

Ivy Lopez

author
#0 lore raw

PATCH 1/1 hwmon: emc1812: reject channel index 0 in device tree config

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.

---
 drivers/hwmon/emc1812.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hwmon/emc1812.c +3 -2
index 68575c27d090..143c3c07dbaa 100644
@@ -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);
 
Signature · 1 line
2.55.0
maintainer NAK
#1 lore raw
Quoted 4 lines · Ivy Lopez

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

#2 lore raw
In reply to Ivy Lopez
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Critical] Rejecting channel index 0 (`reg = 0`) breaks Devicetree ABI backward compatibility and…

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] Rejecting channel index 0 (reg = 0) breaks Devicetree ABI backward compatibility and prevents probing of valid, existing device trees.
- [Low] When reading the reg property fails, the error message logs an unread, stale reg_nr value, misdirecting debugging efforts. --

--- Patch [1]: [PATCH] hwmon: emc1812: reject channel index 0 in device tree config --- commit f33e5fdce14729c5f30dbfaad69487c1d7f783de
Author: Ivy Lopez <[email protected]>

hwmon: emc1812: reject channel index 0 in device tree config

This commit explicitly rejects channel index 0 in child nodes to prevent the internal diode label from being overwritten. It also updates the error message to include the invalid index.

drivers/hwmon/emc1812.c static int emc1812_parse_fw_config(struct emc1812_data *data, struct device *dev · line 812

Quoted 9 lines
drivers/hwmon/emc1812.c +1 -1
@@ -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)

[Severity: Critical]
Does adding reg_nr == 0 break Devicetree ABI backward compatibility?

If there are existing device trees that specify a child node for the internal sensor (channel@0), emc1812_parse_fw_config() will now return -EINVAL during probe and fail to load the driver.

drivers/hwmon/emc1812.c static int emc1812_parse_fw_config(struct emc1812_data *data, struct device *dev · line 815

Quoted 4 lines
drivers/hwmon/emc1812.c +2 -1
 			return dev_err_probe(dev, -EINVAL,
-					     "The index is higher then the chip supports\n");
+					"Invalid channel index %u\n",
+					reg_nr);

[Severity: Low]
If fwnode_property_read_u32() fails and returns a non-zero error code (ret != 0), is it safe to print reg_nr?

If the child node is missing the reg property, fwnode_property_read_u32() leaves reg_nr unmodified. The error message would then log a stale reg_nr value from the previous iteration of the loop, which might misdirect debugging efforts.

Quoted 3 lines
drivers/hwmon/emc1812.c +0 -0
 		/* Mark channel as active */
 		set_bit(reg_nr, &data->active_ch_mask);
 
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1