mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] leds: sgm3140: Put the child node reference on success
@ 2026-11-25 13:40 Cong Nguyen
  2026-11-25 15:15 ` Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: Cong Nguyen @ 2026-11-25 13:40 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek; +Cc: Luca Weiss, linux-leds, linux-kernel

sgm3140_probe() gets the LED child node with device_get_next_child_node(),
which returns it with its reference count raised. The error path puts the
reference, but a successful probe returns before reaching that code, so the
reference is never dropped. The v4l2 flash sub-device takes its own
reference on the node, and the LED class device only stores the pointer,
so nothing else needs the probe's reference after probe returns.

Put the reference before returning success.

Fixes: cef8ec8cbd21 ("leds: add sgm3140 driver")
Signed-off-by: Cong Nguyen <congnt264@gmail.com>
---
 drivers/leds/flash/leds-sgm3140.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/flash/leds-sgm3140.c b/drivers/leds/flash/leds-sgm3140.c
index 107d02c3137f..5bc21b192d74 100644
--- a/drivers/leds/flash/leds-sgm3140.c
+++ b/drivers/leds/flash/leds-sgm3140.c
@@ -273,7 +273,8 @@ static int sgm3140_probe(struct platform_device *pdev)
 		goto err;
 	}
 
-	return ret;
+	fwnode_handle_put(child_node);
+	return 0;
 
 err:
 	fwnode_handle_put(child_node);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] leds: sgm3140: Put the child node reference on success
  2026-11-25 13:40 [PATCH] leds: sgm3140: Put the child node reference on success Cong Nguyen
@ 2026-11-25 15:15 ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2026-11-25 15:15 UTC (permalink / raw)
  To: Cong Nguyen, linux-leds, Lee Jones, Pavel Machek; +Cc: LKML, Luca Weiss

…
> Put the reference before returning success.

Please avoid a bit of duplicate source.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v7.4-rc4#n526


How do you think about to apply the attribute “__free(fwnode_handle_put)”
also in the implementation of the function “sgm3140_probe”?
https://elixir.bootlin.com/linux/v7.4-rc1/source/include/linux/property.h#L229
https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/leds/flash/leds-sgm3140.c#L185-L281

Regards,
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 13:40 [PATCH] leds: sgm3140: Put the child node reference on success Cong Nguyen
2026-11-25 15:15 ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®