Commit 4186ecf8 authored by Arjan van de Ven's avatar Arjan van de Ven Committed by Greg Kroah-Hartman
Browse files

[PATCH] USB: convert a bunch of USB semaphores to mutexes



the patch below converts a bunch of semaphores-used-as-mutex in the USB
code to mutexes
Signed-off-by: default avatarArjan van de Ven <arjan@infradead.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 35cce732
......@@ -60,6 +60,7 @@
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <linux/usb.h>
#include <linux/usb_cdc.h>
......@@ -80,7 +81,7 @@ static struct usb_driver acm_driver;
static struct tty_driver *acm_tty_driver;
static struct acm *acm_table[ACM_TTY_MINORS];
static DECLARE_MUTEX(open_sem);
static DEFINE_MUTEX(open_mutex);
#define ACM_READY(acm) (acm && acm->dev && acm->used)
......@@ -431,8 +432,8 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
int rv = -EINVAL;
int i;
dbg("Entering acm_tty_open.\n");
down(&open_sem);
mutex_lock(&open_mutex);
acm = acm_table[tty->index];
if (!acm || !acm->dev)
......@@ -474,14 +475,14 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
done:
err_out:
up(&open_sem);
mutex_unlock(&open_mutex);
return rv;
full_bailout:
usb_kill_urb(acm->ctrlurb);
bail_out:
acm->used--;
up(&open_sem);
mutex_unlock(&open_mutex);
return -EIO;
}
......@@ -507,7 +508,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
if (!acm || !acm->used)
return;
down(&open_sem);
mutex_lock(&open_mutex);
if (!--acm->used) {
if (acm->dev) {
acm_set_control(acm, acm->ctrlout = 0);
......@@ -518,7 +519,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
} else
acm_tty_unregister(acm);
}
up(&open_sem);
mutex_unlock(&open_mutex);
}
static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
......@@ -1013,9 +1014,9 @@ static void acm_disconnect(struct usb_interface *intf)
return;
}
down(&open_sem);
mutex_lock(&open_mutex);
if (!usb_get_intfdata(intf)) {
up(&open_sem);
mutex_unlock(&open_mutex);
return;
}
acm->dev = NULL;
......@@ -1045,11 +1046,11 @@ static void acm_disconnect(struct usb_interface *intf)
if (!acm->used) {
acm_tty_unregister(acm);
up(&open_sem);
mutex_unlock(&open_mutex);
return;
}
up(&open_sem);
mutex_unlock(&open_mutex);
if (acm->tty)
tty_hangup(acm->tty);
......
......@@ -55,6 +55,7 @@
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/lp.h>
#include <linux/mutex.h>
#undef DEBUG
#include <linux/usb.h>
......@@ -223,7 +224,7 @@ static int usblp_cache_device_id_string(struct usblp *usblp);
/* forward reference to make our lives easier */
static struct usb_driver usblp_driver;
static DECLARE_MUTEX(usblp_sem); /* locks the existence of usblp's */
static DEFINE_MUTEX(usblp_mutex); /* locks the existence of usblp's */
/*
* Functions for usblp control messages.
......@@ -351,7 +352,7 @@ static int usblp_open(struct inode *inode, struct file *file)
if (minor < 0)
return -ENODEV;
down (&usblp_sem);
mutex_lock (&usblp_mutex);
retval = -ENODEV;
intf = usb_find_interface(&usblp_driver, minor);
......@@ -399,7 +400,7 @@ static int usblp_open(struct inode *inode, struct file *file)
}
}
out:
up (&usblp_sem);
mutex_unlock (&usblp_mutex);
return retval;
}
......@@ -425,13 +426,13 @@ static int usblp_release(struct inode *inode, struct file *file)
{
struct usblp *usblp = file->private_data;
down (&usblp_sem);
mutex_lock (&usblp_mutex);
usblp->used = 0;
if (usblp->present) {
usblp_unlink_urbs(usblp);
} else /* finish cleanup from disconnect */
usblp_cleanup (usblp);
up (&usblp_sem);
mutex_unlock (&usblp_mutex);
return 0;
}
......@@ -1152,7 +1153,7 @@ static void usblp_disconnect(struct usb_interface *intf)
device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
down (&usblp_sem);
mutex_lock (&usblp_mutex);
down (&usblp->sem);
usblp->present = 0;
usb_set_intfdata (intf, NULL);
......@@ -1166,7 +1167,7 @@ static void usblp_disconnect(struct usb_interface *intf)
if (!usblp->used)
usblp_cleanup (usblp);
up (&usblp_sem);
mutex_unlock (&usblp_mutex);
}
static struct usb_device_id usblp_ids [] = {
......
......@@ -57,6 +57,7 @@
#include <linux/usb.h>
#include <linux/smp_lock.h>
#include <linux/usbdevice_fs.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
#include "usb.h"
......@@ -570,7 +571,7 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
if (!access_ok(VERIFY_WRITE, buf, nbytes))
return -EFAULT;
down (&usb_bus_list_lock);
mutex_lock(&usb_bus_list_lock);
/* print devices for all busses */
list_for_each_entry(bus, &usb_bus_list, bus_list) {
/* recurse through all children of the root hub */
......@@ -580,12 +581,12 @@ static ssize_t usb_device_read(struct file *file, char __user *buf, size_t nbyte
ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0);
usb_unlock_device(bus->root_hub);
if (ret < 0) {
up(&usb_bus_list_lock);
mutex_unlock(&usb_bus_list_lock);
return ret;
}
total_written += ret;
}
up (&usb_bus_list_lock);
mutex_unlock(&usb_bus_list_lock);
return total_written;
}
......
......@@ -34,6 +34,7 @@
#include <asm/scatterlist.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/mutex.h>
#include <asm/irq.h>
#include <asm/byteorder.h>
......@@ -93,7 +94,7 @@ struct usb_busmap {
static struct usb_busmap busmap;
/* used when updating list of hcds */
DECLARE_MUTEX (usb_bus_list_lock); /* exported only for usbfs */
DEFINE_MUTEX(usb_bus_list_lock); /* exported only for usbfs */
EXPORT_SYMBOL_GPL (usb_bus_list_lock);
/* used for controlling access to virtual root hubs */
......@@ -761,14 +762,14 @@ static int usb_register_bus(struct usb_bus *bus)
{
int busnum;
down (&usb_bus_list_lock);
mutex_lock(&usb_bus_list_lock);
busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1);
if (busnum < USB_MAXBUS) {
set_bit (busnum, busmap.busmap);
bus->busnum = busnum;
} else {
printk (KERN_ERR "%s: too many buses\n", usbcore_name);
up(&usb_bus_list_lock);
mutex_unlock(&usb_bus_list_lock);
return -E2BIG;
}
......@@ -776,7 +777,7 @@ static int usb_register_bus(struct usb_bus *bus)
bus->controller, "usb_host%d", busnum);
if (IS_ERR(bus->class_dev)) {
clear_bit(busnum, busmap.busmap);
up(&usb_bus_list_lock);
mutex_unlock(&usb_bus_list_lock);
return PTR_ERR(bus->class_dev);
}
......@@ -784,7 +785,7 @@ static int usb_register_bus(struct usb_bus *bus)
/* Add it to the local list of buses */
list_add (&bus->bus_list, &usb_bus_list);
up (&usb_bus_list_lock);
mutex_unlock(&usb_bus_list_lock);
usb_notify_add_bus(bus);
......@@ -809,9 +810,9 @@ static void usb_deregister_bus (struct usb_bus *bus)
* controller code, as well as having it call this when cleaning
* itself up
*/
down (&usb_bus_list_lock);
mutex_lock(&usb_bus_list_lock);
list_del (&bus->bus_list);
up (&usb_bus_list_lock);
mutex_unlock(&usb_bus_list_lock);
usb_notify_remove_bus(bus);
......@@ -844,14 +845,14 @@ static int register_root_hub (struct usb_device *usb_dev,
set_bit (devnum, usb_dev->bus->devmap.devicemap);
usb_set_device_state(usb_dev, USB_STATE_ADDRESS);
down (&usb_bus_list_lock);
mutex_lock(&usb_bus_list_lock);
usb_dev->bus->root_hub = usb_dev;
usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
if (retval != sizeof usb_dev->descriptor) {
usb_dev->bus->root_hub = NULL;
up (&usb_bus_list_lock);
mutex_unlock(&usb_bus_list_lock);
dev_dbg (parent_dev, "can't read %s device descriptor %d\n",
usb_dev->dev.bus_id, retval);
return (retval < 0) ? retval : -EMSGSIZE;
......@@ -863,7 +864,7 @@ static int register_root_hub (struct usb_device *usb_dev,
dev_err (parent_dev, "can't register root hub for %s, %d\n",
usb_dev->dev.bus_id, retval);
}
up (&usb_bus_list_lock);
mutex_unlock(&usb_bus_list_lock);
if (retval == 0) {
spin_lock_irq (&hcd_root_hub_lock);
......@@ -1891,9 +1892,9 @@ void usb_remove_hcd(struct usb_hcd *hcd)
hcd->rh_registered = 0;
spin_unlock_irq (&hcd_root_hub_lock);
down(&usb_bus_list_lock);
mutex_lock(&usb_bus_list_lock);
usb_disconnect(&hcd->self.root_hub);
up(&usb_bus_list_lock);
mutex_unlock(&usb_bus_list_lock);
hcd->poll_rh = 0;
del_timer_sync(&hcd->rh_timer);
......
......@@ -364,7 +364,7 @@ extern void usb_set_device_state(struct usb_device *udev,
/* exported only within usbcore */
extern struct list_head usb_bus_list;
extern struct semaphore usb_bus_list_lock;
extern struct mutex usb_bus_list_lock;
extern wait_queue_head_t usb_kill_urb_queue;
extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
......
......@@ -22,6 +22,7 @@
#include <linux/usb.h>
#include <linux/usbdevice_fs.h>
#include <linux/kthread.h>
#include <linux/mutex.h>
#include <asm/semaphore.h>
#include <asm/uaccess.h>
......@@ -2162,7 +2163,7 @@ static int
hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
int retry_counter)
{
static DECLARE_MUTEX(usb_address0_sem);
static DEFINE_MUTEX(usb_address0_mutex);
struct usb_device *hdev = hub->hdev;
int i, j, retval;
......@@ -2183,7 +2184,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
if (oldspeed == USB_SPEED_LOW)
delay = HUB_LONG_RESET_TIME;
down(&usb_address0_sem);
mutex_lock(&usb_address0_mutex);
/* Reset the device; full speed may morph to high speed */
retval = hub_port_reset(hub, port1, udev, delay);
......@@ -2381,7 +2382,7 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
fail:
if (retval)
hub_port_disable(hub, port1, 0);
up(&usb_address0_sem);
mutex_unlock(&usb_address0_mutex);
return retval;
}
......
......@@ -13,16 +13,17 @@
#include <linux/kernel.h>
#include <linux/notifier.h>
#include <linux/usb.h>
#include <linux/mutex.h>
#include "usb.h"
static struct notifier_block *usb_notifier_list;
static DECLARE_MUTEX(usb_notifier_lock);
static DEFINE_MUTEX(usb_notifier_lock);
static void usb_notifier_chain_register(struct notifier_block **list,
struct notifier_block *n)
{
down(&usb_notifier_lock);
mutex_lock(&usb_notifier_lock);
while (*list) {
if (n->priority > (*list)->priority)
break;
......@@ -30,13 +31,13 @@ static void usb_notifier_chain_register(struct notifier_block **list,
}
n->next = *list;
*list = n;
up(&usb_notifier_lock);
mutex_unlock(&usb_notifier_lock);
}
static void usb_notifier_chain_unregister(struct notifier_block **nl,
struct notifier_block *n)
{
down(&usb_notifier_lock);
mutex_lock(&usb_notifier_lock);
while ((*nl)!=NULL) {
if ((*nl)==n) {
*nl = n->next;
......@@ -45,7 +46,7 @@ static void usb_notifier_chain_unregister(struct notifier_block **nl,
nl=&((*nl)->next);
}
exit:
up(&usb_notifier_lock);
mutex_unlock(&usb_notifier_lock);
}
static int usb_notifier_call_chain(struct notifier_block **n,
......@@ -54,7 +55,7 @@ static int usb_notifier_call_chain(struct notifier_block **n,
int ret=NOTIFY_DONE;
struct notifier_block *nb = *n;
down(&usb_notifier_lock);
mutex_lock(&usb_notifier_lock);
while (nb) {
ret = nb->notifier_call(nb,val,v);
if (ret&NOTIFY_STOP_MASK) {
......@@ -63,7 +64,7 @@ static int usb_notifier_call_chain(struct notifier_block **n,
nb = nb->next;
}
exit:
up(&usb_notifier_lock);
mutex_unlock(&usb_notifier_lock);
return ret;
}
......
......@@ -33,6 +33,7 @@
#include <linux/errno.h>
#include <linux/smp_lock.h>
#include <linux/usb.h>
#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/scatterlist.h>
......@@ -639,7 +640,7 @@ struct usb_device *usb_find_device(u16 vendor_id, u16 product_id)
struct usb_bus *bus;
struct usb_device *dev = NULL;
down(&usb_bus_list_lock);
mutex_lock(&usb_bus_list_lock);
for (buslist = usb_bus_list.next;
buslist != &usb_bus_list;
buslist = buslist->next) {
......@@ -653,7 +654,7 @@ struct usb_device *usb_find_device(u16 vendor_id, u16 product_id)
goto exit;
}
exit:
up(&usb_bus_list_lock);
mutex_unlock(&usb_bus_list_lock);
return dev;
}
......
......@@ -96,6 +96,7 @@
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <linux/wait.h>
#include <linux/mutex.h>
#include <linux/usb.h>
#include <linux/fs.h>
......@@ -169,7 +170,7 @@ struct mdc800_data
int out_count; // Bytes in the buffer
int open; // Camera device open ?
struct semaphore io_lock; // IO -lock
struct mutex io_lock; // IO -lock
char in [8]; // Command Input Buffer
int in_count;
......@@ -497,7 +498,7 @@ static int mdc800_usb_probe (struct usb_interface *intf,
info ("Found Mustek MDC800 on USB.");
down (&mdc800->io_lock);
mutex_lock(&mdc800->io_lock);
retval = usb_register_dev(intf, &mdc800_class);
if (retval) {
......@@ -542,7 +543,7 @@ static int mdc800_usb_probe (struct usb_interface *intf,
mdc800->state=READY;
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
usb_set_intfdata(intf, mdc800);
return 0;
......@@ -620,7 +621,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
int retval=0;
int errn=0;
down (&mdc800->io_lock);
mutex_lock(&mdc800->io_lock);
if (mdc800->state == NOT_CONNECTED)
{
......@@ -656,7 +657,7 @@ static int mdc800_device_open (struct inode* inode, struct file *file)
dbg ("Mustek MDC800 device opened.");
error_out:
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return errn;
}
......@@ -669,7 +670,7 @@ static int mdc800_device_release (struct inode* inode, struct file *file)
int retval=0;
dbg ("Mustek MDC800 device closed.");
down (&mdc800->io_lock);
mutex_lock(&mdc800->io_lock);
if (mdc800->open && (mdc800->state != NOT_CONNECTED))
{
usb_kill_urb(mdc800->irq_urb);
......@@ -682,7 +683,7 @@ static int mdc800_device_release (struct inode* inode, struct file *file)
retval=-EIO;
}
up(&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return retval;
}
......@@ -695,21 +696,21 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
size_t left=len, sts=len; /* single transfer size */
char __user *ptr = buf;
down (&mdc800->io_lock);
mutex_lock(&mdc800->io_lock);
if (mdc800->state == NOT_CONNECTED)
{
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EBUSY;
}
if (mdc800->state == WORKING)
{
warn ("Illegal State \"working\" reached during read ?!");
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EBUSY;
}
if (!mdc800->open)
{
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EBUSY;
}
......@@ -717,7 +718,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
{
if (signal_pending (current))
{
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EINTR;
}
......@@ -736,7 +737,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
if (usb_submit_urb (mdc800->download_urb, GFP_KERNEL))
{
err ("Can't submit download urb (status=%i)",mdc800->download_urb->status);
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return len-left;
}
wait_event_timeout(mdc800->download_wait, mdc800->downloaded,
......@@ -745,14 +746,14 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
if (mdc800->download_urb->status != 0)
{
err ("request download-bytes fails (status=%i)",mdc800->download_urb->status);
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return len-left;
}
}
else
{
/* No more bytes -> that's an error*/
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EIO;
}
}
......@@ -761,7 +762,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
/* Copy Bytes */
if (copy_to_user(ptr, &mdc800->out [mdc800->out_ptr],
sts)) {
up(&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EFAULT;
}
ptr+=sts;
......@@ -770,7 +771,7 @@ static ssize_t mdc800_device_read (struct file *file, char __user *buf, size_t l
}
}
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return len-left;
}
......@@ -785,15 +786,15 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
{
size_t i=0;
down (&mdc800->io_lock);
mutex_lock(&mdc800->io_lock);
if (mdc800->state != READY)
{
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EBUSY;
}
if (!mdc800->open )
{
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EBUSY;
}
......@@ -802,13 +803,13 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
unsigned char c;
if (signal_pending (current))
{
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EINTR;
}
if(get_user(c, buf+i))
{
up(&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EFAULT;
}
......@@ -829,7 +830,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
}
else
{
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EIO;
}
......@@ -841,7 +842,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
if (mdc800_usb_waitForIRQ (0,TO_GET_READY))
{
err ("Camera didn't get ready.\n");
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EIO;
}
......@@ -853,7 +854,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
if (usb_submit_urb (mdc800->write_urb, GFP_KERNEL))
{
err ("submitting write urb fails (status=%i)", mdc800->write_urb->status);
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EIO;
}
wait_event_timeout(mdc800->write_wait, mdc800->written, TO_WRITE_GET_READY*HZ/1000);
......@@ -861,7 +862,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
if (mdc800->state == WORKING)
{
usb_kill_urb(mdc800->write_urb);
up (&mdc800->io_lock);
mutex_unlock(&mdc800->io_lock);
return -EIO;
}
......@@ -873,7 +874,7 @@ static ssize_t mdc800_device_write (struct file *file, const char __user *buf, s
{
err ("call 0x07 before 0x05,0x3e");
mdc800->state=READY;
up (&mdc800->io_lock);
mutex_unlock