]> git.hungrycats.org Git - linux/commit
leds: flash: mt6360: Fix device_for_each_child_node() refcounting in error paths
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>
Thu, 26 Sep 2024 23:20:52 +0000 (01:20 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 9 Dec 2024 09:33:08 +0000 (10:33 +0100)
commit4a44bcb73a0ba4b4f46b6e89a7755aaaaeb041b1
tree682042bd3efe5def9a6dbc0cf08c577558690b75
parent5294e8abd46cc1acbd03b00ce97e3034f67c08bc
leds: flash: mt6360: Fix device_for_each_child_node() refcounting in error paths

commit 73b03b27736e440e3009fe1319cbc82d2cd1290c upstream.

The device_for_each_child_node() macro requires explicit calls to
fwnode_handle_put() upon early exits to avoid memory leaks, and in
this case the error paths are handled after jumping to
'out_flash_realease', which misses that required call to
to decrement the refcount of the child node.

A more elegant and robust solution is using the scoped variant of the
loop, which automatically handles such early exits.

Fix the child node refcounting in the error paths by using
device_for_each_child_node_scoped().

Cc: stable@vger.kernel.org
Fixes: 679f8652064b ("leds: Add mt6360 driver")
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-1-95c0614b38c8@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/leds/flash/leds-mt6360.c