dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robin Murphy <robin.murphy@arm.com>
To: Nishka Dasgupta <nishkadg.linux@gmail.com>,
	okaya@kernel.org, agross@kernel.org, vkoul@kernel.org,
	dan.j.williams@intel.com, linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org, dmaengine@vger.kernel.org
Subject: Re: [PATCH] dma: qcom: hidma_mgmt: Add of_node_put() before goto
Date: Tue, 23 Jul 2019 13:02:12 +0100	[thread overview]
Message-ID: <b5b76ef6-c5f3-bab0-e981-cd47c7264959@arm.com> (raw)
In-Reply-To: <20190723103543.7888-1-nishkadg.linux@gmail.com>

On 23/07/2019 11:35, Nishka Dasgupta wrote:
> Each iteration of for_each_available_child_of_node puts the previous
> node, but in the case of a goto from the middle of the loop, there is
> no put, thus causing a memory leak. Add an of_node_put before the
> goto in 4 places.

Why not just add it once at the "out" label itself? (Consider the 
conditions for the loop terminating naturally)

And if you're cleaning up the refcounting here anyway then I'd also note 
that the reference held by the loop iterator makes the extra get/put 
inside that loop entirely redundant. It's always worth taking a look at 
the wider context rather than just blindly focusing on what a given 
script picks up - it's fairly rare that a piece of code has one obvious 
issue but is otherwise perfect.

Robin.

> Issue found with Coccinelle.
> 
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---
>   drivers/dma/qcom/hidma_mgmt.c | 13 ++++++++++---
>   1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/qcom/hidma_mgmt.c b/drivers/dma/qcom/hidma_mgmt.c
> index 3022d66e7a33..209adc6ceabe 100644
> --- a/drivers/dma/qcom/hidma_mgmt.c
> +++ b/drivers/dma/qcom/hidma_mgmt.c
> @@ -362,16 +362,22 @@ static int __init hidma_mgmt_of_populate_channels(struct device_node *np)
>   		struct platform_device *new_pdev;
>   
>   		ret = of_address_to_resource(child, 0, &res[0]);
> -		if (!ret)
> +		if (!ret) {
> +			of_node_put(child);
>   			goto out;
> +		}
>   
>   		ret = of_address_to_resource(child, 1, &res[1]);
> -		if (!ret)
> +		if (!ret) {
> +			of_node_put(child);
>   			goto out;
> +		}
>   
>   		ret = of_irq_to_resource(child, 0, &res[2]);
> -		if (ret <= 0)
> +		if (ret <= 0) {
> +			of_node_put(child);
>   			goto out;
> +		}
>   
>   		memset(&pdevinfo, 0, sizeof(pdevinfo));
>   		pdevinfo.fwnode = &child->fwnode;
> @@ -386,6 +392,7 @@ static int __init hidma_mgmt_of_populate_channels(struct device_node *np)
>   		new_pdev = platform_device_register_full(&pdevinfo);
>   		if (IS_ERR(new_pdev)) {
>   			ret = PTR_ERR(new_pdev);
> +			of_node_put(child);
>   			goto out;
>   		}
>   		of_node_get(child);
> 

  reply	other threads:[~2019-07-23 12:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 10:35 [PATCH] dma: qcom: hidma_mgmt: Add of_node_put() before goto Nishka Dasgupta
2019-07-23 12:02 ` Robin Murphy [this message]
2019-07-23 15:45   ` Sinan Kaya
2019-07-24  8:05   ` Nishka Dasgupta
2019-07-24 10:10     ` Robin Murphy

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=b5b76ef6-c5f3-bab0-e981-cd47c7264959@arm.com \
    --to=robin.murphy@arm.com \
    --cc=agross@kernel.org \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=nishkadg.linux@gmail.com \
    --cc=okaya@kernel.org \
    --cc=vkoul@kernel.org \
    /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).