Skip to contentSkip to conversation

usb: core: endpoint: Fix error path

PATCH In review Rahul Ruikar 3 participants 8 messages Oct 2, 2010 – Oct 7, 2010 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: core: endpoint: Fix error path

In function usb_create_ep_devs()
call put_device() when device_register() fails.

---
 drivers/usb/core/endpoint.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/usb/core/endpoint.c +3 -1
index 3788e73..cab126d 100644
@@ -195,8 +195,10 @@ int usb_create_ep_devs(struct device *parent,
 	device_enable_async_suspend(&ep_dev->dev);
 
 	retval = device_register(&ep_dev->dev);
-	if (retval)
+	if (retval) {
+		put_device(&ep_dev->dev);
 		goto error_register;
+	}
 
 	endpoint->ep_dev = ep_dev;
 	return retval;
Signature · 1 line
1.7.2.3
#1 lore raw

2010/10/2 Rahul Ruikar <[email protected]>:

Quoted 15 lines

In function usb_create_ep_devs()
call put_device() when device_register() fails.

---
 drivers/usb/core/endpoint.c |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/usb/core/endpoint.c +0 -0
index 3788e73..cab126d 100644
@@ -195,8 +195,10 @@ int usb_create_ep_devs(struct device *parent,
        device_enable_async_suspend(&ep_dev->dev);
 

drivers/usb/core/endpoint.c int usb_create_ep_devs(struct device *parent,

Quoted 10 lines
drivers/usb/core/endpoint.c +3 -2
        retval = device_register(&ep_dev->dev);
-       if (retval)
+       if (retval) {
+               put_device(&ep_dev->dev);
                goto error_register;
+       }
 
        endpoint->ep_dev = ep_dev;
        return retval;
--

You should replace kfree(ep_dev) with put_device(&ep_dev->dev), otherwise double free will be triggered.

So you need to revise the patch...

Signature · 1 line
Lei Ming
#2 lore raw

revised patch attached.

Thanks
- Rahul Ruikar

Quoted 30 lines · Ming Lei

2010/10/2 Rahul Ruikar <[email protected]>:

Quoted 15 lines

In function usb_create_ep_devs()
call put_device() when device_register() fails.

---
 drivers/usb/core/endpoint.c |    4 +++-

 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/usb/core/endpoint.c +0 -0
index 3788e73..cab126d 100644
@@ -195,8 +195,10 @@ int usb_create_ep_devs(struct device *parent,
        device_enable_async_suspend(&ep_dev->dev);
 

drivers/usb/core/endpoint.c int usb_create_ep_devs(struct device *parent,

Quoted 10 lines
drivers/usb/core/endpoint.c +3 -2
        retval = device_register(&ep_dev->dev);
-       if (retval)
+       if (retval) {
+               put_device(&ep_dev->dev);
                goto error_register;
+       }
 
        endpoint->ep_dev = ep_dev;
        return retval;
--

You should replace kfree(ep_dev) with put_device(&ep_dev->dev), otherwise double free will be triggered.

Quoted 5 lines

So you need to revise the patch...

--
Lei Ming

From 0189060361c503a78ffb055f9c2ab50ac5a1a88e Mon Sep 17 00:00:00 2001
From: Rahul Ruikar <[email protected]>
Date: Sat, 2 Oct 2010 14:09:39 +0530
Subject: [PATCH] usb: core: endpoint: Fix error path

In function usb_create_ep_devs()
call put_device() when device_register() fails.

---
 drivers/usb/core/endpoint.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/usb/core/endpoint.c +1 -1
index 3788e73..9da2505 100644
@@ -202,7 +202,7 @@ int usb_create_ep_devs(struct device *parent,
 	return retval;
 
 error_register:
-	kfree(ep_dev);
+	put_device(&ep_dev->dev);
 exit:
 	return retval;
 }
Signature · 1 line
1.7.2.3
#4 lore raw

Thanks Ming.
I have certain doubts related to device_unregister()

In some of USB related code..
kfree() is called after device_unregister() ... device_unregister() also internally calls put_device()... is that correct behavior or I'm missing something here..
ex.
file : drivers/usb/gadget/fsl_udc_core.c
function : static int __init fsl_udc_probe(struct platform_device *pdev)

- Rahul Ruikar

Quoted 8 lines · Ming Lei

2010/10/2 Rahul Ruikar <[email protected]>:

Quoted 1 line

revised patch attached.

--
Lei Ming

#5 lore raw

2010/10/2 Rahul Ruikar <[email protected]>:

Quoted 7 lines

Thanks Ming.
I have certain doubts related to device_unregister()

In some of USB related code..
kfree() is called after device_unregister() ...  device_unregister() also internally calls put_device()... is that correct behavior or I'm missing something here..

If no other external reference to device before put_device in device_unregister, dev.release will be called from put_device to free something, which depends on your implement for dev.release.

Quoted 3 lines

ex.
file : drivers/usb/gadget/fsl_udc_core.c
function : static int __init fsl_udc_probe(struct platform_device *pdev)

Once reaches err_unregister, double free of udc_controller may be triggered, so fix should be needed.

Signature · 1 line
Lei Ming
#7 lore raw

Sent in another mail now.

- Rahul Ruikar

Quoted 9 lines · Greg KH
Quoted 1 line · Rahul Ruikar

revised patch attached.

Please resend it in the proper format.

thanks,

greg k-h