linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrice CHOTARD <patrice.chotard@st.com>
To: Nishka Dasgupta <nishkadg.linux@gmail.com>,
	"balbi@kernel.org" <balbi@kernel.org>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Subject: Re: [PATCH 1/2] usb: dwc3: st: Add of_node_put() before return in probe function
Date: Mon, 26 Aug 2019 07:46:28 +0000	[thread overview]
Message-ID: <7e0bcd72-0de0-bc04-03e0-f850d6457e7e@st.com> (raw)
In-Reply-To: <20190819072436.31402-1-nishkadg.linux@gmail.com>

Hi Nishka

On 8/19/19 9:24 AM, Nishka Dasgupta wrote:
> The local variable child in the function st_dwc3_probe takes the return
> value of of_get_child_by_name, which gets a node and does not put it. If
> the function returns without releasing child, this could cause a memory
> error. Hence put child as soon as there is no more use for it. Also
> create a new label, err_node_put, just before label undo_softreset; so
> that err_node_put puts child. In between initialisation of child and its
> first put, modify all statements that go to undo_softreset to now go to
> err_node_put instead, from where they can fall through to
> undo_softreset.
> Issue found with Coccinelle.
>
> Signed-off-by: Nishka Dasgupta <nishkadg.linux@gmail.com>
> ---
>  drivers/usb/dwc3/dwc3-st.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c
> index 16081383c401..6f52c749cd58 100644
> --- a/drivers/usb/dwc3/dwc3-st.c
> +++ b/drivers/usb/dwc3/dwc3-st.c
> @@ -255,24 +255,25 @@ static int st_dwc3_probe(struct platform_device *pdev)
>  	if (!child) {
>  		dev_err(&pdev->dev, "failed to find dwc3 core node\n");
>  		ret = -ENODEV;
> -		goto undo_softreset;
> +		goto err_node_put;
>  	}
>  
>  	/* Allocate and initialize the core */
>  	ret = of_platform_populate(node, NULL, NULL, dev);
>  	if (ret) {
>  		dev_err(dev, "failed to add dwc3 core\n");
> -		goto undo_softreset;
> +		goto err_node_put;
>  	}
>  
>  	child_pdev = of_find_device_by_node(child);
>  	if (!child_pdev) {
>  		dev_err(dev, "failed to find dwc3 core device\n");
>  		ret = -ENODEV;
> -		goto undo_softreset;
> +		goto err_node_put;
>  	}
>  
>  	dwc3_data->dr_mode = usb_get_dr_mode(&child_pdev->dev);
> +	of_node_put(child);
>  
>  	/*
>  	 * Configure the USB port as device or host according to the static
> @@ -292,6 +293,8 @@ static int st_dwc3_probe(struct platform_device *pdev)
>  	platform_set_drvdata(pdev, dwc3_data);
>  	return 0;
>  
> +err_node_put:
> +	of_node_put(child);
>  undo_softreset:
>  	reset_control_assert(dwc3_data->rstc_rst);
>  undo_powerdown:


Reviewed-by: Patrice Chotard <patrice.chotard@st.com>

Thanks

      parent reply	other threads:[~2019-08-26  7:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19  7:24 [PATCH 1/2] usb: dwc3: st: Add of_node_put() before return in probe function Nishka Dasgupta
2019-08-19  7:24 ` [PATCH 2/2] usb: dwc3: st: Add of_dev_put() " Nishka Dasgupta
2019-08-26  7:47   ` Patrice CHOTARD
2019-08-26  7:46 ` Patrice CHOTARD [this message]

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=7e0bcd72-0de0-bc04-03e0-f850d6457e7e@st.com \
    --to=patrice.chotard@st.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nishkadg.linux@gmail.com \
    /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).