All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: rawnand: gpmi: fix reference count leak in gpmi ops
@ 2020-11-07 11:05 Zhang Qilong
  2020-11-09 23:23 ` Han Xu
  2020-11-19 21:20 ` Miquel Raynal
  0 siblings, 2 replies; 3+ messages in thread
From: Zhang Qilong @ 2020-11-07 11:05 UTC (permalink / raw)
  To: han.xu, miquel.raynal, vigneshr; +Cc: richard, linux-mtd

pm_runtime_get_sync() will increment pm usage at first and it
will resume the device later. If runtime of the device has
error or device is in inaccessible state(or other error state),
resume operation will fail. If we do not call put operation to
decrease the reference, it will result in reference leak in
the two functions(gpmi_init and gpmi_nfc_exec_op). Moreover,
this device cannot enter the idle state and always stay busy or
other non-idle state later. So we fixed it through adding
pm_runtime_put_noidle.

Fixes: 5bc6bb603b4d0 ("mtd: rawnand: gpmi: Fix suspend/resume problem")

Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
---
 drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
index dc8104e67506..b5f46f214a58 100644
--- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
+++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
@@ -149,8 +149,10 @@ static int gpmi_init(struct gpmi_nand_data *this)
 	int ret;
 
 	ret = pm_runtime_get_sync(this->dev);
-	if (ret < 0)
+	if (ret < 0) {
+		pm_runtime_put_noidle(this->dev);
 		return ret;
+	}
 
 	ret = gpmi_reset_block(r->gpmi_regs, false);
 	if (ret)
@@ -2263,8 +2265,10 @@ static int gpmi_nfc_exec_op(struct nand_chip *chip,
 		this->transfers[i].direction = DMA_NONE;
 
 	ret = pm_runtime_get_sync(this->dev);
-	if (ret < 0)
+	if (ret < 0) {
+		pm_runtime_put_noidle(this->dev);
 		return ret;
+	}
 
 	/*
 	 * This driver currently supports only one NAND chip. Plus, dies share
-- 
2.25.4


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* RE: [PATCH] mtd: rawnand: gpmi: fix reference count leak in gpmi ops
  2020-11-07 11:05 [PATCH] mtd: rawnand: gpmi: fix reference count leak in gpmi ops Zhang Qilong
@ 2020-11-09 23:23 ` Han Xu
  2020-11-19 21:20 ` Miquel Raynal
  1 sibling, 0 replies; 3+ messages in thread
From: Han Xu @ 2020-11-09 23:23 UTC (permalink / raw)
  To: Zhang Qilong, miquel.raynal, vigneshr; +Cc: richard, linux-mtd



> -----Original Message-----
> From: Zhang Qilong <zhangqilong3@huawei.com>
> Sent: Saturday, November 7, 2020 5:06 AM
> To: Han Xu <han.xu@nxp.com>; miquel.raynal@bootlin.com; vigneshr@ti.com
> Cc: richard@nod.at; linux-mtd@lists.infradead.org
> Subject: [PATCH] mtd: rawnand: gpmi: fix reference count leak in gpmi ops
> 
> pm_runtime_get_sync() will increment pm usage at first and it will resume the
> device later. If runtime of the device has error or device is in inaccessible
> state(or other error state), resume operation will fail. If we do not call put
> operation to decrease the reference, it will result in reference leak in the two
> functions(gpmi_init and gpmi_nfc_exec_op). Moreover, this device cannot enter
> the idle state and always stay busy or other non-idle state later. So we fixed it
> through adding pm_runtime_put_noidle.
> 
> Fixes: 5bc6bb603b4d0 ("mtd: rawnand: gpmi: Fix suspend/resume problem")
> 
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
>  drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> index dc8104e67506..b5f46f214a58 100644
> --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c
> @@ -149,8 +149,10 @@ static int gpmi_init(struct gpmi_nand_data *this)
>  	int ret;
> 
>  	ret = pm_runtime_get_sync(this->dev);
> -	if (ret < 0)
> +	if (ret < 0) {
> +		pm_runtime_put_noidle(this->dev);
>  		return ret;
> +	}
> 
>  	ret = gpmi_reset_block(r->gpmi_regs, false);
>  	if (ret)
> @@ -2263,8 +2265,10 @@ static int gpmi_nfc_exec_op(struct nand_chip *chip,
>  		this->transfers[i].direction = DMA_NONE;
> 
>  	ret = pm_runtime_get_sync(this->dev);
> -	if (ret < 0)
> +	if (ret < 0) {
> +		pm_runtime_put_noidle(this->dev);
>  		return ret;
> +	}
> 

Acked-by: Han Xu <han.xu@nxp.com>

>  	/*
>  	 * This driver currently supports only one NAND chip. Plus, dies share
> --
> 2.25.4


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

* Re: [PATCH] mtd: rawnand: gpmi: fix reference count leak in gpmi ops
  2020-11-07 11:05 [PATCH] mtd: rawnand: gpmi: fix reference count leak in gpmi ops Zhang Qilong
  2020-11-09 23:23 ` Han Xu
@ 2020-11-19 21:20 ` Miquel Raynal
  1 sibling, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2020-11-19 21:20 UTC (permalink / raw)
  To: Zhang Qilong, han.xu, miquel.raynal, vigneshr; +Cc: richard, linux-mtd

On Sat, 2020-11-07 at 11:05:52 UTC, Zhang Qilong wrote:
> pm_runtime_get_sync() will increment pm usage at first and it
> will resume the device later. If runtime of the device has
> error or device is in inaccessible state(or other error state),
> resume operation will fail. If we do not call put operation to
> decrease the reference, it will result in reference leak in
> the two functions(gpmi_init and gpmi_nfc_exec_op). Moreover,
> this device cannot enter the idle state and always stay busy or
> other non-idle state later. So we fixed it through adding
> pm_runtime_put_noidle.
> 
> Fixes: 5bc6bb603b4d0 ("mtd: rawnand: gpmi: Fix suspend/resume problem")
> 
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> Acked-by: Han Xu <han.xu@nxp.com>

Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.

Miquel

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

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

end of thread, other threads:[~2020-11-19 21:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-07 11:05 [PATCH] mtd: rawnand: gpmi: fix reference count leak in gpmi ops Zhang Qilong
2020-11-09 23:23 ` Han Xu
2020-11-19 21:20 ` Miquel Raynal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.