linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Vladimir Zapolskiy <vz@mleia.com>
Cc: Haotian Zhang <vulab@iscas.ac.cn>,
	 richard@nod.at,  vigneshr@ti.com, piotr.wojtaszczyk@timesys.com,
	 dmitry.torokhov@gmail.com, linux-mtd@lists.infradead.org,
	 linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: rawnand: lpc32xx_slc: fix GPIO descriptor leak on probe error and remove
Date: Tue, 04 Nov 2025 09:27:51 +0100	[thread overview]
Message-ID: <871pmeb3so.fsf@bootlin.com> (raw)
In-Reply-To: <57f7989d-6f05-4b1b-a31b-4b1dca308ffb@mleia.com> (Vladimir Zapolskiy's message of "Mon, 3 Nov 2025 18:21:47 +0200")

Hello,

On 03/11/2025 at 18:21:47 +02, Vladimir Zapolskiy <vz@mleia.com> wrote:

> On 10/28/25 11:47, Haotian Zhang wrote:
>> The driver calls gpiod_get_optional() in the probe function but
>> never calls gpiod_put() in the remove function or in the probe
>> error path. This leads to a GPIO descriptor resource leak.
>> The lpc32xx_mlc.c driver in the same directory handles this
>> correctly by calling gpiod_put() on both paths.
>> Add gpiod_put() in the remove function and in the probe error path
>> to fix the resource leak.
>> Fixes: 6b923db2867c ("mtd: rawnand: lpc32xx_slc: switch to using gpiod
>> API")
>> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
>
> The problem is well identified, thank you for the fix.
>
>> ---
>>   drivers/mtd/nand/raw/lpc32xx_slc.c | 2 ++
>>   1 file changed, 2 insertions(+)
>> diff --git a/drivers/mtd/nand/raw/lpc32xx_slc.c
>> b/drivers/mtd/nand/raw/lpc32xx_slc.c
>> index b54d76547ffb..fea3705a2138 100644
>> --- a/drivers/mtd/nand/raw/lpc32xx_slc.c
>> +++ b/drivers/mtd/nand/raw/lpc32xx_slc.c
>> @@ -937,6 +937,7 @@ static int lpc32xx_nand_probe(struct platform_device *pdev)
>>   	dma_release_channel(host->dma_chan);
>>   enable_wp:
>>   	lpc32xx_wp_enable(host);
>> +	gpiod_put(host->wp_gpio);
>>     	return res;
>>   }
>> @@ -962,6 +963,7 @@ static void lpc32xx_nand_remove(struct platform_device *pdev)
>>   	writel(tmp, SLC_CTRL(host->io_base));
>>     	lpc32xx_wp_enable(host);
>> +	gpiod_put(host->wp_gpio);
>>   }
>>     static int lpc32xx_nand_resume(struct platform_device *pdev)
>
> The fix can be greatly improved though, I kindly ask you to send v2 by switching
> from gpiod_get_optional() to resource managed
> devm_gpiod_get_optional().

I've already applied this fix, however I will welcome a follow-up patch.

Thanks,
Miquèl


  reply	other threads:[~2025-11-04  8:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-28  9:47 [PATCH] mtd: rawnand: lpc32xx_slc: fix GPIO descriptor leak on probe error and remove Haotian Zhang
2025-10-28 15:59 ` Miquel Raynal
2025-11-03 16:21 ` Vladimir Zapolskiy
2025-11-04  8:27   ` Miquel Raynal [this message]
2025-11-04  1:40 ` [PATCH v2] mtd: rawnand: lpc32xx_slc: fix GPIO descriptor leak Haotian Zhang
2025-11-04  8:55   ` Miquel Raynal
2025-11-04 18:33   ` Markus Elfring

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=871pmeb3so.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=piotr.wojtaszczyk@timesys.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    --cc=vulab@iscas.ac.cn \
    --cc=vz@mleia.com \
    /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;
as well as URLs for NNTP newsgroup(s).