Skip to content

Commit

Permalink
USB: misc: legousbtower: semaphore to mutex
Browse files Browse the repository at this point in the history
The dev->sem conforms to mutex style usage. This patch converts it to use
the struct mutex type, and new API.

There is also a small style fix around this comment,

/* unlock here as tower_delete frees dev */

Where I broke the line up to meet the 80 char limit.

Signed-off-by: Daniel Walker <dwalker@mvista.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Daniel Walker authored and Greg Kroah-Hartman committed Feb 1, 2008
1 parent da0e8fb commit 18bcbcf
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions drivers/usb/misc/legousbtower.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static DEFINE_MUTEX(open_disc_mutex);

/* Structure to hold all of our device specific stuff */
struct lego_usb_tower {
struct semaphore sem; /* locks this structure */
struct mutex lock; /* locks this structure */
struct usb_device* udev; /* save off the usb device pointer */
unsigned char minor; /* the starting minor number for this device */

Expand Down Expand Up @@ -361,7 +361,7 @@ static int tower_open (struct inode *inode, struct file *file)
}

/* lock this device */
if (down_interruptible (&dev->sem)) {
if (mutex_lock_interruptible(&dev->lock)) {
mutex_unlock(&open_disc_mutex);
retval = -ERESTARTSYS;
goto exit;
Expand Down Expand Up @@ -421,7 +421,7 @@ static int tower_open (struct inode *inode, struct file *file)
file->private_data = dev;

unlock_exit:
up (&dev->sem);
mutex_unlock(&dev->lock);

exit:
dbg(2, "%s: leave, return value %d ", __FUNCTION__, retval);
Expand All @@ -448,7 +448,7 @@ static int tower_release (struct inode *inode, struct file *file)
}

mutex_lock(&open_disc_mutex);
if (down_interruptible (&dev->sem)) {
if (mutex_lock_interruptible(&dev->lock)) {
retval = -ERESTARTSYS;
goto exit;
}
Expand All @@ -460,7 +460,9 @@ static int tower_release (struct inode *inode, struct file *file)
}
if (dev->udev == NULL) {
/* the device was unplugged before the file was released */
up (&dev->sem); /* unlock here as tower_delete frees dev */

/* unlock here as tower_delete frees dev */
mutex_unlock(&dev->lock);
tower_delete (dev);
goto exit;
}
Expand All @@ -473,7 +475,7 @@ static int tower_release (struct inode *inode, struct file *file)
dev->open_count = 0;

unlock_exit:
up (&dev->sem);
mutex_unlock(&dev->lock);

exit:
mutex_unlock(&open_disc_mutex);
Expand Down Expand Up @@ -586,7 +588,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,
dev = (struct lego_usb_tower *)file->private_data;

/* lock this object */
if (down_interruptible (&dev->sem)) {
if (mutex_lock_interruptible(&dev->lock)) {
retval = -ERESTARTSYS;
goto exit;
}
Expand Down Expand Up @@ -653,7 +655,7 @@ static ssize_t tower_read (struct file *file, char __user *buffer, size_t count,

unlock_exit:
/* unlock the device */
up (&dev->sem);
mutex_unlock(&dev->lock);

exit:
dbg(2, "%s: leave, return value %d", __FUNCTION__, retval);
Expand All @@ -675,7 +677,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t
dev = (struct lego_usb_tower *)file->private_data;

/* lock this object */
if (down_interruptible (&dev->sem)) {
if (mutex_lock_interruptible(&dev->lock)) {
retval = -ERESTARTSYS;
goto exit;
}
Expand Down Expand Up @@ -737,7 +739,7 @@ static ssize_t tower_write (struct file *file, const char __user *buffer, size_t

unlock_exit:
/* unlock the device */
up (&dev->sem);
mutex_unlock(&dev->lock);

exit:
dbg(2, "%s: leave, return value %d", __FUNCTION__, retval);
Expand Down Expand Up @@ -862,7 +864,7 @@ static int tower_probe (struct usb_interface *interface, const struct usb_device
goto exit;
}

init_MUTEX (&dev->sem);
mutex_init(&dev->lock);

dev->udev = udev;
dev->open_count = 0;
Expand Down Expand Up @@ -1007,16 +1009,16 @@ static void tower_disconnect (struct usb_interface *interface)
/* give back our minor */
usb_deregister_dev (interface, &tower_class);

down (&dev->sem);
mutex_lock(&dev->lock);
mutex_unlock(&open_disc_mutex);

/* if the device is not opened, then we clean up right now */
if (!dev->open_count) {
up (&dev->sem);
mutex_unlock(&dev->lock);
tower_delete (dev);
} else {
dev->udev = NULL;
up (&dev->sem);
mutex_unlock(&dev->lock);
}

info("LEGO USB Tower #%d now disconnected", (minor - LEGO_USB_TOWER_MINOR_BASE));
Expand Down

0 comments on commit 18bcbcf

Please sign in to comment.