};
MODULE_DEVICE_TABLE (usb, tower_table);
+static DEFINE_MUTEX(open_disc_mutex);
#define LEGO_USB_TOWER_MINOR_BASE 160
goto exit;
}
+ mutex_lock(&open_disc_mutex);
dev = usb_get_intfdata(interface);
if (!dev) {
+ mutex_unlock(&open_disc_mutex);
retval = -ENODEV;
goto exit;
}
/* lock this device */
if (down_interruptible (&dev->sem)) {
+ mutex_unlock(&open_disc_mutex);
retval = -ERESTARTSYS;
goto exit;
}
+
/* allow opening only once */
if (dev->open_count) {
+ mutex_unlock(&open_disc_mutex);
retval = -EBUSY;
goto unlock_exit;
}
dev->open_count = 1;
+ mutex_unlock(&open_disc_mutex);
/* reset the tower */
result = usb_control_msg (dev->udev,
if (dev == NULL) {
dbg(1, "%s: object is NULL", __FUNCTION__);
retval = -ENODEV;
- goto exit;
+ goto exit_nolock;
}
+ mutex_lock(&open_disc_mutex);
if (down_interruptible (&dev->sem)) {
retval = -ERESTARTSYS;
goto exit;
up (&dev->sem);
exit:
+ mutex_unlock(&open_disc_mutex);
+exit_nolock:
dbg(2, "%s: leave, return value %d", __FUNCTION__, retval);
return retval;
}
dbg(2, "%s: enter", __FUNCTION__);
dev = usb_get_intfdata (interface);
+ mutex_lock(&open_disc_mutex);
usb_set_intfdata (interface, NULL);
minor = dev->minor;
usb_deregister_dev (interface, &tower_class);
down (&dev->sem);
+ mutex_unlock(&open_disc_mutex);
/* if the device is not opened, then we clean up right now */
if (!dev->open_count) {