From 5b06470816fb5e658e81db2a55b530ff2ba711c9 Mon Sep 17 00:00:00 2001 From: Oliver Neukum Date: Thu, 8 Feb 2007 15:42:53 +0100 Subject: [PATCH] USB: fix autosuspend race in skeleton driver as the skeleton driver was made ready for autosuspend a race condition was introduced. The reference to get device must be gotten before the autosuspend counter is upped, as this operation may sleep, dropping BKL. Dropping BKL means that the pointer to the device may become invalid. Here's the fix. Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- drivers/usb/usb-skeleton.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c index 296b091cf168..46929a1b6f24 100644 --- a/drivers/usb/usb-skeleton.c +++ b/drivers/usb/usb-skeleton.c @@ -90,14 +90,16 @@ static int skel_open(struct inode *inode, struct file *file) goto exit; } - /* prevent the device from being autosuspended */ - retval = usb_autopm_get_interface(interface); - if (retval) - goto exit; - /* increment our usage count for the device */ kref_get(&dev->kref); + /* prevent the device from being autosuspended */ + retval = usb_autopm_get_interface(interface); + if (retval) { + kref_put(&dev->kref, skel_delete); + goto exit; + } + /* save our object in the file's private structure */ file->private_data = dev;