]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
USB: fix autosuspend race in skeleton driver
authorOliver Neukum <oneukum@suse.de>
Thu, 8 Feb 2007 14:42:53 +0000 (15:42 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 16 Feb 2007 23:32:19 +0000 (15:32 -0800)
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 <oneukum@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/usb-skeleton.c

index 296b091cf168c7e460ec70db19ac7dcc18a777c1..46929a1b6f24e44ba8566c46d0db993dfd113439 100644 (file)
@@ -90,13 +90,15 @@ static int skel_open(struct inode *inode, struct file *file)
                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)
+       if (retval) {
+               kref_put(&dev->kref, skel_delete);
                goto exit;
-
-       /* increment our usage count for the device */
-       kref_get(&dev->kref);
+       }
 
        /* save our object in the file's private structure */
        file->private_data = dev;