Commit 5b06470816fb5e658e81db2a55b530ff2ba711c9
Committed by
Greg Kroah-Hartman
1 parent
57e4f041bf
Exists in
master
and in
7 other branches
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 <oneukum@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Showing 1 changed file with 6 additions and 4 deletions Side-by-side Diff
drivers/usb/usb-skeleton.c
... | ... | @@ -90,13 +90,15 @@ |
90 | 90 | goto exit; |
91 | 91 | } |
92 | 92 | |
93 | + /* increment our usage count for the device */ | |
94 | + kref_get(&dev->kref); | |
95 | + | |
93 | 96 | /* prevent the device from being autosuspended */ |
94 | 97 | retval = usb_autopm_get_interface(interface); |
95 | - if (retval) | |
98 | + if (retval) { | |
99 | + kref_put(&dev->kref, skel_delete); | |
96 | 100 | goto exit; |
97 | - | |
98 | - /* increment our usage count for the device */ | |
99 | - kref_get(&dev->kref); | |
101 | + } | |
100 | 102 | |
101 | 103 | /* save our object in the file's private structure */ |
102 | 104 | file->private_data = dev; |