From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Guangshuo Li <lgs201920130244@gmail.com>
Cc: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Jonathan Cameron <jic23@kernel.org>,
Luca Weiss <luca@lucaweiss.eu>,
linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2] leds: flash: sgm3140: fix child node reference leak
Date: Mon, 21 Sep 2026 14:54:23 +0300 [thread overview]
Message-ID: <20260921115423.GD1466037@killaraus.ideasonboard.com> (raw)
In-Reply-To: <20260921092128.346375-1-lgs201920130244@gmail.com>
Why did you submit a v2 ignoring my latest comments on v1 ?
On Mon, Sep 21, 2026 at 05:21:28PM +0800, Guangshuo Li wrote:
> sgm3140_probe() obtains a reference to the LED child node with
> device_get_next_child_node(), but the reference is not released after a
> successful probe.
>
> The child node is also passed to devm_led_classdev_flash_register_ext().
> The LED class device stores the fwnode without taking a reference of its
> own, so the reference obtained by sgm3140_probe() must remain valid until
> the LED class device is unregistered.
>
> Manage the child node reference with a devm action registered before the
> LED class device. This ensures that the LED class device is unregistered
> before the child node reference is dropped, while also handling probe
> failure and device removal.
>
> Fixes: cef8ec8cbd21 ("leds: add sgm3140 driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
> v2:
> - Keep the child node reference alive until the LED class device is
> unregistered, as pointed out by Laurent Pinchart.
> - Manage the reference with a devm action registered before the LED
> class device registration.
>
> drivers/leds/flash/leds-sgm3140.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/leds/flash/leds-sgm3140.c b/drivers/leds/flash/leds-sgm3140.c
> index dc6840357370..973676b1dbb1 100644
> --- a/drivers/leds/flash/leds-sgm3140.c
> +++ b/drivers/leds/flash/leds-sgm3140.c
> @@ -182,6 +182,11 @@ static void sgm3140_init_v4l2_flash_config(struct sgm3140 *priv,
> }
> #endif
>
> +static void sgm3140_fwnode_put(void *data)
> +{
> + fwnode_handle_put(data);
> +}
> +
> static int sgm3140_probe(struct platform_device *pdev)
> {
> struct sgm3140 *priv;
> @@ -220,6 +225,10 @@ static int sgm3140_probe(struct platform_device *pdev)
> "No fwnode child node found for connected LED.\n");
> return -EINVAL;
> }
> + ret = devm_add_action_or_reset(&pdev->dev, sgm3140_fwnode_put,
> + child_node);
> + if (ret)
> + return ret;
>
> ret = fwnode_property_read_u32(child_node, "flash-max-timeout-us",
> &priv->max_timeout);
> @@ -276,7 +285,6 @@ static int sgm3140_probe(struct platform_device *pdev)
> return ret;
>
> err:
> - fwnode_handle_put(child_node);
> return ret;
> }
>
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2026-09-21 11:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 9:21 Guangshuo Li
2026-09-21 11:02 ` Sakari Ailus
2026-09-21 11:54 ` Laurent Pinchart [this message]
2026-09-22 6:57 ` Guangshuo Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260921115423.GD1466037@killaraus.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=jic23@kernel.org \
--cc=lee@kernel.org \
--cc=lgs201920130244@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=luca@lucaweiss.eu \
--cc=pavel@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®