diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2010-01-10 04:15:03 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-03-02 17:54:13 -0500 |
commit | f7410ced7f931bb1ad79d1336412cf7b7a33cb14 (patch) | |
tree | c25966dee9bb112a8e9495cd161a4db95c1785a7 /drivers/usb/core/hub.c | |
parent | d23356da714595b888686d22cd19061323c09190 (diff) |
USB: Move hcd free_dev call into usb_disconnect to fix oops
USB: Move hcd free_dev call into usb_disconnect
I found a way to oops the kernel:
1. Open a USB device through devio.
2. Remove the hcd module in the host kernel.
3. Close the devio file descriptor.
The problem is that closing the file descriptor does usb_release_dev
as it is the last reference. usb_release_dev then tries to invoke
the hcd free_dev function (or rather dereferencing the hcd driver
struct). This causes an oops as the hcd driver has already been
unloaded so the struct is gone.
This patch tries to fix this by bringing the free_dev call earlier
and into usb_disconnect. I have verified that repeating the
above steps no longer crashes with this patch applied.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/core/hub.c')
-rw-r--r-- | drivers/usb/core/hub.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index 0e0a190bbd0..e198ff8a11c 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c | |||
@@ -1524,6 +1524,15 @@ static void update_address(struct usb_device *udev, int devnum) | |||
1524 | udev->devnum = devnum; | 1524 | udev->devnum = devnum; |
1525 | } | 1525 | } |
1526 | 1526 | ||
1527 | static void hub_free_dev(struct usb_device *udev) | ||
1528 | { | ||
1529 | struct usb_hcd *hcd = bus_to_hcd(udev->bus); | ||
1530 | |||
1531 | /* Root hubs aren't real devices, so don't free HCD resources */ | ||
1532 | if (hcd->driver->free_dev && udev->parent) | ||
1533 | hcd->driver->free_dev(hcd, udev); | ||
1534 | } | ||
1535 | |||
1527 | /** | 1536 | /** |
1528 | * usb_disconnect - disconnect a device (usbcore-internal) | 1537 | * usb_disconnect - disconnect a device (usbcore-internal) |
1529 | * @pdev: pointer to device being disconnected | 1538 | * @pdev: pointer to device being disconnected |
@@ -1592,6 +1601,8 @@ void usb_disconnect(struct usb_device **pdev) | |||
1592 | *pdev = NULL; | 1601 | *pdev = NULL; |
1593 | spin_unlock_irq(&device_state_lock); | 1602 | spin_unlock_irq(&device_state_lock); |
1594 | 1603 | ||
1604 | hub_free_dev(udev); | ||
1605 | |||
1595 | put_device(&udev->dev); | 1606 | put_device(&udev->dev); |
1596 | } | 1607 | } |
1597 | 1608 | ||
@@ -3166,6 +3177,7 @@ loop_disable: | |||
3166 | loop: | 3177 | loop: |
3167 | usb_ep0_reinit(udev); | 3178 | usb_ep0_reinit(udev); |
3168 | release_address(udev); | 3179 | release_address(udev); |
3180 | hub_free_dev(udev); | ||
3169 | usb_put_dev(udev); | 3181 | usb_put_dev(udev); |
3170 | if ((status == -ENOTCONN) || (status == -ENOTSUPP)) | 3182 | if ((status == -ENOTCONN) || (status == -ENOTSUPP)) |
3171 | break; | 3183 | break; |