mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srini@kernel.org>
To: Wentao Liang <vulab@iscas.ac.cn>, a.fatoum@pengutronix.de
Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	rafal@milecki.pl, srini@kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] nvmem: u-boot-env: Fix mtd reference leak in u_boot_env_probe()
Date: Fri, 18 Sep 2026 22:44:12 +0100	[thread overview]
Message-ID: <91b23d5a-b923-48da-9ab5-bf2aabe1afca@kernel.org> (raw)
In-Reply-To: <20260917123839.2151503-1-vulab@iscas.ac.cn>



On 9/17/26 1:38 PM, Wentao Liang wrote:
> of_get_mtd_device_by_node() takes a reference on the returned MTD device
> that the caller has to drop with put_mtd_device(). The probe function
> returns early when devm_nvmem_register() or u_boot_env_parse() fails
> without releasing that reference, so add the missing put_mtd_device()
> calls on both error paths.
> 
> Fixes: d5542923f200 ("nvmem: add driver handling U-Boot environment variables")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
>  drivers/nvmem/u-boot-env.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/nvmem/u-boot-env.c b/drivers/nvmem/u-boot-env.c
> index ced414fc9e60..893fbd2a8520 100644
> --- a/drivers/nvmem/u-boot-env.c
> +++ b/drivers/nvmem/u-boot-env.c
> @@ -52,6 +52,7 @@ static int u_boot_env_probe(struct platform_device *pdev)
>  	struct device *dev = &pdev->dev;
>  	struct device_node *np = dev->of_node;
>  	struct u_boot_env *priv;
> +	int ret;
>  
>  	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
>  	if (!priv)
> @@ -71,10 +72,16 @@ static int u_boot_env_probe(struct platform_device *pdev)
>  	config.size = priv->mtd->size;
>  
>  	priv->nvmem = devm_nvmem_register(dev, &config);
> -	if (IS_ERR(priv->nvmem))
> +	if (IS_ERR(priv->nvmem)) {
> +		put_mtd_device(priv->mtd);
>  		return PTR_ERR(priv->nvmem);
> +	}
> +
> +	ret = u_boot_env_parse(dev, priv->nvmem, priv->format);
> +	if (ret)
> +		put_mtd_device(priv->mtd);
>  
> -	return u_boot_env_parse(dev, priv->nvmem, priv->format);
> +	return ret;

consider devm_add_action_or_reset() that should cover one more case this
patch missed.

--srini
>  }
>  
>  static const struct of_device_id u_boot_env_of_match_table[] = {


      reply	other threads:[~2026-09-18 21:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 12:38 Wentao Liang
2026-09-18 21:44 ` Srinivas Kandagatla [this message]

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=91b23d5a-b923-48da-9ab5-bf2aabe1afca@kernel.org \
    --to=srini@kernel.org \
    --cc=a.fatoum@pengutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafal@milecki.pl \
    --cc=stable@vger.kernel.org \
    --cc=vulab@iscas.ac.cn \
    /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®