mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
To: Xin Xiong <xiongx18@fudan.edu.cn>
Cc: Mark Brown <broonie@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	yuanxzhang@fudan.edu.cn, Xiyu Yang <xiyuyang19@fudan.edu.cn>,
	Xin Tan <tanxin.ctf@gmail.com>,
	linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] spi: uniphier: fix reference count leak in uniphier_spi_probe()
Date: Wed, 26 Jan 2022 10:19:13 +0900	[thread overview]
Message-ID: <e3283f14-adf1-ac3c-3454-80ff68b7d71f@socionext.com> (raw)
In-Reply-To: <20220125101214.35677-1-xiongx18@fudan.edu.cn>

On 2022/01/25 19:12, Xin Xiong wrote:
> The issue happens in several error paths in uniphier_spi_probe().
> When either dma_get_slave_caps() or devm_spi_register_master() returns
> an error code, the function forgets to decrease the refcount of both
> `dma_rx` and `dma_tx` objects, which may lead to refcount leaks.
> 
> Fix it by decrementing the reference count of specific objects in
> those error paths.

Looks good to me.

Reviewed-by: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>

And it is necessary to add the following line to this according to
Documentation/process/submitting-patches.rst.

Fixes: 28d1dddc59f6 ("spi: uniphier: Add DMA transfer mode support")

Thank you,

> Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
> ---
>   drivers/spi/spi-uniphier.c | 18 ++++++++++++++----
>   1 file changed, 14 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/spi/spi-uniphier.c b/drivers/spi/spi-uniphier.c
> index 342ee8d2c..cc0da4822 100644
> --- a/drivers/spi/spi-uniphier.c
> +++ b/drivers/spi/spi-uniphier.c
> @@ -726,7 +726,7 @@ static int uniphier_spi_probe(struct platform_device
> *pdev)
>   		if (ret) {
>   			dev_err(&pdev->dev, "failed to get TX DMA
> capacities: %d\n",
>   				ret);
> -			goto out_disable_clk;
> +			goto out_release_dma;
>   		}
>   		dma_tx_burst = caps.max_burst;
>   	}
> @@ -735,7 +735,7 @@ static int uniphier_spi_probe(struct platform_device
> *pdev)
>   	if (IS_ERR_OR_NULL(master->dma_rx)) {
>   		if (PTR_ERR(master->dma_rx) == -EPROBE_DEFER) {
>   			ret = -EPROBE_DEFER;
> -			goto out_disable_clk;
> +			goto out_release_dma;
>   		}
>   		master->dma_rx = NULL;
>   		dma_rx_burst = INT_MAX;
> @@ -744,7 +744,7 @@ static int uniphier_spi_probe(struct platform_device
> *pdev)
>   		if (ret) {
>   			dev_err(&pdev->dev, "failed to get RX DMA
> capacities: %d\n",
>   				ret);
> -			goto out_disable_clk;
> +			goto out_release_dma;
>   		}
>   		dma_rx_burst = caps.max_burst;
>   	}
> @@ -753,10 +753,20 @@ static int uniphier_spi_probe(struct platform_device
> *pdev)
>   
>   	ret = devm_spi_register_master(&pdev->dev, master);
>   	if (ret)
> -		goto out_disable_clk;
> +		goto out_release_dma;
>   
>   	return 0;
>   
> +out_release_dma:
> +	if (!IS_ERR_OR_NULL(master->dma_rx)) {
> +		dma_release_channel(master->dma_rx);
> +		master->dma_rx = NULL;
> +	}
> +	if (!IS_ERR_OR_NULL(master->dma_tx)) {
> +		dma_release_channel(master->dma_tx);
> +		master->dma_tx = NULL;
> +	}
> +
>   out_disable_clk:
>   	clk_disable_unprepare(priv->clk);
>   
> 

-- 
---
Best Regards
Kunihiko Hayashi

       reply	other threads:[~2022-01-26  1:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220125101214.35677-1-xiongx18@fudan.edu.cn>
2022-01-26  1:19 ` Kunihiko Hayashi [this message]
2022-01-28 15:59 ` Mark Brown

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=e3283f14-adf1-ac3c-3454-80ff68b7d71f@socionext.com \
    --to=hayashi.kunihiko@socionext.com \
    --cc=broonie@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=tanxin.ctf@gmail.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 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®