* [PATCH v4] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init
@ 2022-03-04 8:53 Xin Xiong
2022-03-09 15:08 ` Claudiu.Beznea
2022-03-14 16:00 ` Miquel Raynal
0 siblings, 2 replies; 3+ messages in thread
From: Xin Xiong @ 2022-03-04 8:53 UTC (permalink / raw)
To: Tudor Ambarus, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Boris Brezillon, linux-mtd, linux-arm-kernel,
linux-kernel
Cc: yuanxzhang, Xin Xiong, Xiyu Yang, Xin Tan
The reference counting issue happens in several error handling paths
on a refcounted object "nc->dmac". In these paths, the function simply
returns the error code, forgetting to balance the reference count of
"nc->dmac", increased earlier by dma_request_channel(), which may
cause refcount leaks.
Fix it by decrementing the refcount of specific object in those error
paths.
Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
Co-developed-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
Co-developed-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
---
V3 -> V4: Removed useless condition check
V2 -> V3: Removed redundant lines
V1 -> V2: Rewrited the error handling block
---
drivers/mtd/nand/raw/atmel/nand-controller.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c
index f3276ee9e4fe..ddd93bc38ea6 100644
--- a/drivers/mtd/nand/raw/atmel/nand-controller.c
+++ b/drivers/mtd/nand/raw/atmel/nand-controller.c
@@ -2060,13 +2060,15 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
nc->mck = of_clk_get(dev->parent->of_node, 0);
if (IS_ERR(nc->mck)) {
dev_err(dev, "Failed to retrieve MCK clk\n");
- return PTR_ERR(nc->mck);
+ ret = PTR_ERR(nc->mck);
+ goto out_release_dma;
}
np = of_parse_phandle(dev->parent->of_node, "atmel,smc", 0);
if (!np) {
dev_err(dev, "Missing or invalid atmel,smc property\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto out_release_dma;
}
nc->smc = syscon_node_to_regmap(np);
@@ -2074,10 +2076,16 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
if (IS_ERR(nc->smc)) {
ret = PTR_ERR(nc->smc);
dev_err(dev, "Could not get SMC regmap (err = %d)\n", ret);
- return ret;
+ goto out_release_dma;
}
return 0;
+
+out_release_dma:
+ if (nc->dmac)
+ dma_release_channel(nc->dmac);
+
+ return ret;
}
static int
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init
2022-03-04 8:53 [PATCH v4] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init Xin Xiong
@ 2022-03-09 15:08 ` Claudiu.Beznea
2022-03-14 16:00 ` Miquel Raynal
1 sibling, 0 replies; 3+ messages in thread
From: Claudiu.Beznea @ 2022-03-09 15:08 UTC (permalink / raw)
To: xiongx18, Tudor.Ambarus, miquel.raynal, richard, vigneshr,
Nicolas.Ferre, alexandre.belloni, bbrezillon, linux-mtd,
linux-arm-kernel, linux-kernel
Cc: yuanxzhang, xiyuyang19, tanxin.ctf
On 04.03.2022 10:53, Xin Xiong wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> The reference counting issue happens in several error handling paths
> on a refcounted object "nc->dmac". In these paths, the function simply
> returns the error code, forgetting to balance the reference count of
> "nc->dmac", increased earlier by dma_request_channel(), which may
> cause refcount leaks.
>
> Fix it by decrementing the refcount of specific object in those error
> paths.
>
> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
> Co-developed-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Co-developed-by: Xin Tan <tanxin.ctf@gmail.com>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
> Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
> V3 -> V4: Removed useless condition check
> V2 -> V3: Removed redundant lines
> V1 -> V2: Rewrited the error handling block
> ---
> drivers/mtd/nand/raw/atmel/nand-controller.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/raw/atmel/nand-controller.c b/drivers/mtd/nand/raw/atmel/nand-controller.c
> index f3276ee9e4fe..ddd93bc38ea6 100644
> --- a/drivers/mtd/nand/raw/atmel/nand-controller.c
> +++ b/drivers/mtd/nand/raw/atmel/nand-controller.c
> @@ -2060,13 +2060,15 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
> nc->mck = of_clk_get(dev->parent->of_node, 0);
> if (IS_ERR(nc->mck)) {
> dev_err(dev, "Failed to retrieve MCK clk\n");
> - return PTR_ERR(nc->mck);
> + ret = PTR_ERR(nc->mck);
> + goto out_release_dma;
> }
>
> np = of_parse_phandle(dev->parent->of_node, "atmel,smc", 0);
> if (!np) {
> dev_err(dev, "Missing or invalid atmel,smc property\n");
> - return -EINVAL;
> + ret = -EINVAL;
> + goto out_release_dma;
> }
>
> nc->smc = syscon_node_to_regmap(np);
> @@ -2074,10 +2076,16 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
> if (IS_ERR(nc->smc)) {
> ret = PTR_ERR(nc->smc);
> dev_err(dev, "Could not get SMC regmap (err = %d)\n", ret);
> - return ret;
> + goto out_release_dma;
> }
>
> return 0;
> +
> +out_release_dma:
> + if (nc->dmac)
> + dma_release_channel(nc->dmac);
> +
> + return ret;
> }
>
> static int
> --
> 2.25.1
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init
2022-03-04 8:53 [PATCH v4] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init Xin Xiong
2022-03-09 15:08 ` Claudiu.Beznea
@ 2022-03-14 16:00 ` Miquel Raynal
1 sibling, 0 replies; 3+ messages in thread
From: Miquel Raynal @ 2022-03-14 16:00 UTC (permalink / raw)
To: Xin Xiong, Tudor Ambarus, Miquel Raynal, Richard Weinberger,
Vignesh Raghavendra, Nicolas Ferre, Alexandre Belloni,
Claudiu Beznea, Boris Brezillon, linux-mtd, linux-arm-kernel,
linux-kernel
Cc: yuanxzhang, Xiyu Yang, Xin Tan
On Fri, 2022-03-04 at 08:53:32 UTC, Xin Xiong wrote:
> The reference counting issue happens in several error handling paths
> on a refcounted object "nc->dmac". In these paths, the function simply
> returns the error code, forgetting to balance the reference count of
> "nc->dmac", increased earlier by dma_request_channel(), which may
> cause refcount leaks.
>
> Fix it by decrementing the refcount of specific object in those error
> paths.
>
> Fixes: f88fc122cc34 ("mtd: nand: Cleanup/rework the atmel_nand driver")
> Co-developed-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Co-developed-by: Xin Tan <tanxin.ctf@gmail.com>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
> Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
> Reviewed-by: Claudiu Beznea <claudiu.beznea@microchip.com>
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks.
Miquel
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-14 16:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-04 8:53 [PATCH v4] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init Xin Xiong
2022-03-09 15:08 ` Claudiu.Beznea
2022-03-14 16:00 ` Miquel Raynal
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).