Skip to content

Commit

Permalink
USB: BKL removal: rio500
Browse files Browse the repository at this point in the history
This driver had used BKL to guard against disconnect but
was incorrectly converted leaving an SMP race.
BKL was added to disconnect() to fix this race
BKL was removed from ioctl() as the mutex is sufficient
on its own.

Signed-off-by: Oliver Neukum <oliver@neukum.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Oliver Neukum authored and Greg Kroah-Hartman committed Mar 2, 2010
1 parent 5a207b4 commit 511e2d0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/usb/misc/rio500.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,14 @@ static struct rio_usb_data rio_instance;
static int open_rio(struct inode *inode, struct file *file)
{
struct rio_usb_data *rio = &rio_instance;

/* against disconnect() */
lock_kernel();
mutex_lock(&(rio->lock));

if (rio->isopen || !rio->present) {
mutex_unlock(&(rio->lock));
unlock_kernel();
return -EBUSY;
}
rio->isopen = 1;
Expand Down Expand Up @@ -116,7 +119,6 @@ static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)
int retries;
int retval=0;

lock_kernel();
mutex_lock(&(rio->lock));
/* Sanity check to make sure rio is connected, powered, etc */
if (rio->present == 0 || rio->rio_dev == NULL) {
Expand Down Expand Up @@ -255,7 +257,6 @@ static long ioctl_rio(struct file *file, unsigned int cmd, unsigned long arg)

err_out:
mutex_unlock(&(rio->lock));
unlock_kernel();
return retval;
}

Expand Down Expand Up @@ -490,6 +491,7 @@ static void disconnect_rio(struct usb_interface *intf)
struct rio_usb_data *rio = usb_get_intfdata (intf);

usb_set_intfdata (intf, NULL);
lock_kernel();
if (rio) {
usb_deregister_dev(intf, &usb_rio_class);

Expand All @@ -499,6 +501,7 @@ static void disconnect_rio(struct usb_interface *intf)
/* better let it finish - the release will do whats needed */
rio->rio_dev = NULL;
mutex_unlock(&(rio->lock));
unlock_kernel();
return;
}
kfree(rio->ibuf);
Expand All @@ -509,6 +512,7 @@ static void disconnect_rio(struct usb_interface *intf)
rio->present = 0;
mutex_unlock(&(rio->lock));
}
unlock_kernel();
}

static const struct usb_device_id rio_table[] = {
Expand Down

0 comments on commit 511e2d0

Please sign in to comment.