diff mbox

[1/7] USB: core: fix device node leak

Message ID 20170530162554.26159-2-johan@kernel.org (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Johan Hovold May 30, 2017, 4:25 p.m. UTC
Make sure to release any OF device-node reference taken when creating
the USB device.

Note that we currently do not hold a reference to the root hub
device-tree node (i.e. the parent controller node).

Fixes: 69bec7259853 ("USB: core: let USB device know device node")
Cc: stable <stable@vger.kernel.org>	# v4.6
Cc: Peter Chen <peter.chen@nxp.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/core/usb.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Tyrel Datwyler May 30, 2017, 10:55 p.m. UTC | #1
On 05/30/2017 09:25 AM, Johan Hovold wrote:
> Make sure to release any OF device-node reference taken when creating
> the USB device.
> 
> Note that we currently do not hold a reference to the root hub
> device-tree node (i.e. the parent controller node).
> 
> Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> Cc: stable <stable@vger.kernel.org>	# v4.6
> Cc: Peter Chen <peter.chen@nxp.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/core/usb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index 28b053cacc90..62e1906bb2f3 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
>  
>  	usb_destroy_configuration(udev);
>  	usb_release_bos_descriptor(udev);
> +	if (udev->parent)
> +		of_node_put(dev->of_node);

If I'm following the root hub doesn't hold an of_node reference, so does that guarantee
that dev->of_node is NULL for the root hub? If so of_node_put() is safely called with a
NULL reference, making the if(udev->parent) unnecessary, and further no need to remove it
in follow-up patch #5.

-Tyrel

>  	usb_put_hcd(hcd);
>  	kfree(udev->product);
>  	kfree(udev->manufacturer);
>
Johan Hovold May 31, 2017, 8:25 a.m. UTC | #2
On Tue, May 30, 2017 at 03:55:56PM -0700, Tyrel Datwyler wrote:
> On 05/30/2017 09:25 AM, Johan Hovold wrote:
> > Make sure to release any OF device-node reference taken when creating
> > the USB device.
> > 
> > Note that we currently do not hold a reference to the root hub
> > device-tree node (i.e. the parent controller node).
> > 
> > Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> > Cc: stable <stable@vger.kernel.org>	# v4.6
> > Cc: Peter Chen <peter.chen@nxp.com>
> > Signed-off-by: Johan Hovold <johan@kernel.org>
> > ---
> >  drivers/usb/core/usb.c | 2 ++
> >  1 file changed, 2 insertions(+)
> > 
> > diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> > index 28b053cacc90..62e1906bb2f3 100644
> > --- a/drivers/usb/core/usb.c
> > +++ b/drivers/usb/core/usb.c
> > @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
> >  
> >  	usb_destroy_configuration(udev);
> >  	usb_release_bos_descriptor(udev);
> > +	if (udev->parent)
> > +		of_node_put(dev->of_node);
> 
> If I'm following the root hub doesn't hold an of_node reference, so
> does that guarantee that dev->of_node is NULL for the root hub?

No, it may be non-NULL.

> If so of_node_put() is safely called with a NULL reference, making the
> if(udev->parent) unnecessary, and further no need to remove it in
> follow-up patch #5.

So this one is still needed.

Thanks,
Johan
Peter Chen June 5, 2017, 3:35 a.m. UTC | #3
On Tue, May 30, 2017 at 06:25:48PM +0200, Johan Hovold wrote:
> Make sure to release any OF device-node reference taken when creating
> the USB device.
> 
> Note that we currently do not hold a reference to the root hub
> device-tree node (i.e. the parent controller node).
> 
> Fixes: 69bec7259853 ("USB: core: let USB device know device node")
> Cc: stable <stable@vger.kernel.org>	# v4.6
> Cc: Peter Chen <peter.chen@nxp.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>  drivers/usb/core/usb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
> index 28b053cacc90..62e1906bb2f3 100644
> --- a/drivers/usb/core/usb.c
> +++ b/drivers/usb/core/usb.c
> @@ -416,6 +416,8 @@ static void usb_release_dev(struct device *dev)
>  
>  	usb_destroy_configuration(udev);
>  	usb_release_bos_descriptor(udev);
> +	if (udev->parent)
> +		of_node_put(dev->of_node);
>  	usb_put_hcd(hcd);
>  	kfree(udev->product);
>  	kfree(udev->manufacturer);

Acked-by: Peter Chen <peter.chen@nxp.com>
diff mbox

Patch

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index 28b053cacc90..62e1906bb2f3 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -416,6 +416,8 @@  static void usb_release_dev(struct device *dev)
 
 	usb_destroy_configuration(udev);
 	usb_release_bos_descriptor(udev);
+	if (udev->parent)
+		of_node_put(dev->of_node);
 	usb_put_hcd(hcd);
 	kfree(udev->product);
 	kfree(udev->manufacturer);