* [PATCH] hwmon: emc1812: reject channel index 0 in device tree config
@ 2026-07-16 0:25 Ivy Lopez
2026-07-16 0:34 ` Guenter Roeck
2026-07-16 0:37 ` sashiko-bot
0 siblings, 2 replies; 3+ messages in thread
From: Ivy Lopez @ 2026-07-16 0:25 UTC (permalink / raw)
To: marius.cristea, linux; +Cc: linux-hwmon, linux-kernel, 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
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] hwmon: emc1812: reject channel index 0 in device tree config
2026-07-16 0:25 [PATCH] hwmon: emc1812: reject channel index 0 in device tree config Ivy Lopez
@ 2026-07-16 0:34 ` Guenter Roeck
2026-07-16 0:37 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-07-16 0:34 UTC (permalink / raw)
To: Ivy Lopez, marius.cristea; +Cc: linux-hwmon, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hwmon: emc1812: reject channel index 0 in device tree config
2026-07-16 0:25 [PATCH] hwmon: emc1812: reject channel index 0 in device tree config Ivy Lopez
2026-07-16 0:34 ` Guenter Roeck
@ 2026-07-16 0:37 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-07-16 0:37 UTC (permalink / raw)
To: Ivy Lopez; +Cc: linux-hwmon
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 <skunkolee@gmail.com>
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.
> diff --git a/drivers/hwmon/emc1812.c b/drivers/hwmon/emc1812.c
> --- 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)
[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.
> 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.
> /* Mark channel as active */
> set_bit(reg_nr, &data->active_ch_mask);
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260716002543.26711-1-skunkolee@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-16 0:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16 0:25 [PATCH] hwmon: emc1812: reject channel index 0 in device tree config Ivy Lopez
2026-07-16 0:34 ` Guenter Roeck
2026-07-16 0:37 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.