usb: core: endpoint: Fix error path
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
@@ -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
2010/10/2 Rahul Ruikar <[email protected]>:
Quoted 15 lines
In function
usb_create_ep_devs()
callput_device()whendevice_register()fails.Signed-off-by Rahul Ruikar <[email protected]>---
drivers/usb/core/endpoint.c | 4 +++-1 files changed, 3 insertions(+), 1 deletions(-)drivers/usb/core/endpoint.c +0
-0@@ -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
-2retval = 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
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()
callput_device()whendevice_register()fails.Signed-off-by Rahul Ruikar <[email protected]>---
drivers/usb/core/endpoint.c | 4 +++-1 files changed, 3 insertions(+), 1 deletions(-)drivers/usb/core/endpoint.c +0
-0@@ -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
-2retval = 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)withput_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
@@ -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
Ming Lei
Acked-by2010/10/2 Rahul Ruikar <[email protected]>:
Quoted 1 line
revised patch attached.
Signature · 1 line
Lei Ming
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.
Acked-by Ming Lei <[email protected]>--
Lei Ming
2010/10/2 Rahul Ruikar <[email protected]>:
Quoted 7 lines
Thanks Ming.
I have certain doubts related todevice_unregister()In some of USB related code..
kfree()is called afterdevice_unregister()... device_unregister() also internally callsput_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__initfsl_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
Quoted 1 line · Rahul Ruikar
revised patch attached.
Please resend it in the proper format.
thanks,
greg k-h
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