Re: [PATCH] leds: max77705: fix fwnode reference leak in max77705_add_led()

From: Lee Jones

Date: Thu Sep 17 2026 - 09:42:48 EST


On Sun, 06 Sep 2026, Miles Krause via B4 Relay wrote:

> From: Miles Krause <mileskrause5200@xxxxxxxxx>
>
> max77705_add_led() iterates over the multicolor LED's child nodes with
> fwnode_for_each_child_node() and returns directly from inside the loop
> when parsing a child fails:
>
> fwnode_for_each_child_node(np, child) {
> ret = max77705_parse_subled(dev, child, &info[i]);
> if (ret < 0)
> return ret;
> ...
> }
>
> The iterator holds a reference on the current child for the duration of
> each iteration: fwnode_get_next_child_node() takes a reference on the
> node it returns and only drops the previous one when it is called again
> (for the OF backend that is the of_node_put(prev) in
> of_get_next_status_child()). Returning from inside the loop skips that
> final call, so the reference taken for the child that failed to parse is
> never released.
>
> max77705_parse_subled() rejects a missing, zero or out-of-range "reg"
> property and propagates errors from reading "color", so a malformed
> device tree is enough to leak a device_node reference.
>
> Use fwnode_for_each_child_node_scoped() instead, which releases the
> reference on every exit path, and drop the now unused 'child'
> declaration. max77705_led_probe() already uses the equivalent
> device_for_each_child_node_scoped() for the outer loop.
>
> Fixes: aebb5fc9a0d8 ("leds: max77705: Add LEDs support")
> Signed-off-by: Miles Krause <mileskrause5200@xxxxxxxxx>

Beaten to it by this I'm afraid:

4805e5ec50d0 leds: max77705: Use fwnode_for_each_child_node_scoped() in max77705_add_led()

--
Lee Jones