All of lore.kernel.org
 help / color / mirror / Atom feed
From: <Claudiu.Beznea@microchip.com>
To: <xiongx18@fudan.edu.cn>, <Tudor.Ambarus@microchip.com>,
	<miquel.raynal@bootlin.com>, <richard@nod.at>, <vigneshr@ti.com>,
	<Nicolas.Ferre@microchip.com>, <alexandre.belloni@bootlin.com>,
	<bbrezillon@kernel.org>, <linux-mtd@lists.infradead.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Cc: <yuanxzhang@fudan.edu.cn>, <xiyuyang19@fudan.edu.cn>,
	<tanxin.ctf@gmail.com>
Subject: Re: [PATCH v4] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init
Date: Wed, 9 Mar 2022 15:08:48 +0000	[thread overview]
Message-ID: <42569c41-909e-559f-317f-660c6a4ddca0@microchip.com> (raw)
In-Reply-To: <20220304085330.3610-1-xiongx18@fudan.edu.cn>

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
> 


WARNING: multiple messages have this Message-ID (diff)
From: <Claudiu.Beznea@microchip.com>
To: <xiongx18@fudan.edu.cn>, <Tudor.Ambarus@microchip.com>,
	<miquel.raynal@bootlin.com>, <richard@nod.at>, <vigneshr@ti.com>,
	<Nicolas.Ferre@microchip.com>, <alexandre.belloni@bootlin.com>,
	<bbrezillon@kernel.org>, <linux-mtd@lists.infradead.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Cc: <yuanxzhang@fudan.edu.cn>, <xiyuyang19@fudan.edu.cn>,
	<tanxin.ctf@gmail.com>
Subject: Re: [PATCH v4] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init
Date: Wed, 9 Mar 2022 15:08:48 +0000	[thread overview]
Message-ID: <42569c41-909e-559f-317f-660c6a4ddca0@microchip.com> (raw)
In-Reply-To: <20220304085330.3610-1-xiongx18@fudan.edu.cn>

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 MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

WARNING: multiple messages have this Message-ID (diff)
From: <Claudiu.Beznea@microchip.com>
To: <xiongx18@fudan.edu.cn>, <Tudor.Ambarus@microchip.com>,
	<miquel.raynal@bootlin.com>, <richard@nod.at>, <vigneshr@ti.com>,
	<Nicolas.Ferre@microchip.com>, <alexandre.belloni@bootlin.com>,
	<bbrezillon@kernel.org>, <linux-mtd@lists.infradead.org>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Cc: <yuanxzhang@fudan.edu.cn>, <xiyuyang19@fudan.edu.cn>,
	<tanxin.ctf@gmail.com>
Subject: Re: [PATCH v4] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init
Date: Wed, 9 Mar 2022 15:08:48 +0000	[thread overview]
Message-ID: <42569c41-909e-559f-317f-660c6a4ddca0@microchip.com> (raw)
In-Reply-To: <20220304085330.3610-1-xiongx18@fudan.edu.cn>

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

  reply	other threads:[~2022-03-09 15:09 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04  8:53 [PATCH v4] mtd: rawnand: atmel: fix refcount issue in atmel_nand_controller_init Xin Xiong
2022-03-04  8:53 ` Xin Xiong
2022-03-04  8:53 ` Xin Xiong
2022-03-09 15:08 ` Claudiu.Beznea [this message]
2022-03-09 15:08   ` Claudiu.Beznea
2022-03-09 15:08   ` Claudiu.Beznea
2022-03-14 16:00 ` Miquel Raynal
2022-03-14 16:00   ` Miquel Raynal
2022-03-14 16:00   ` Miquel Raynal

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=42569c41-909e-559f-317f-660c6a4ddca0@microchip.com \
    --to=claudiu.beznea@microchip.com \
    --cc=Nicolas.Ferre@microchip.com \
    --cc=Tudor.Ambarus@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=bbrezillon@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=tanxin.ctf@gmail.com \
    --cc=vigneshr@ti.com \
    --cc=xiongx18@fudan.edu.cn \
    --cc=xiyuyang19@fudan.edu.cn \
    --cc=yuanxzhang@fudan.edu.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 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.