USB: Move hcd free_dev call into usb_disconnect to fix oops
authorHerbert Xu <herbert@gondor.apana.org.au>
Sun, 10 Jan 2010 09:15:03 +0000 (20:15 +1100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 15 Mar 2010 15:50:09 +0000 (08:50 -0700)
commit2de6fff1986ff1b9ff8bd77b70d3ae31aab8caf9
treebfb598510b5d4ab1463606e478c19912d2e4a102
parent80218d985163393676d96e3df17f80fde6c8daa8
USB: Move hcd free_dev call into usb_disconnect to fix oops

commit f7410ced7f931bb1ad79d1336412cf7b7a33cb14 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/core/hcd.h
drivers/usb/core/hub.c
drivers/usb/core/usb.c