Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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
Loading
Loading
Loading
Loading
+12 −11
Original line number Original line Diff line number Diff line
@@ -60,6 +60,7 @@
#include <linux/tty_flip.h>
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <linux/module.h>
#include <linux/smp_lock.h>
#include <linux/smp_lock.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <asm/uaccess.h>
#include <linux/usb.h>
#include <linux/usb.h>
#include <linux/usb_cdc.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 tty_driver *acm_tty_driver;
static struct acm *acm_table[ACM_TTY_MINORS];
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)
#define ACM_READY(acm)	(acm && acm->dev && acm->used)


@@ -432,7 +433,7 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
	int i;
	int i;
	dbg("Entering acm_tty_open.\n");
	dbg("Entering acm_tty_open.\n");


	down(&open_sem);
	mutex_lock(&open_mutex);


	acm = acm_table[tty->index];
	acm = acm_table[tty->index];
	if (!acm || !acm->dev)
	if (!acm || !acm->dev)
@@ -474,14 +475,14 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)


done:
done:
err_out:
err_out:
	up(&open_sem);
	mutex_unlock(&open_mutex);
	return rv;
	return rv;


full_bailout:
full_bailout:
	usb_kill_urb(acm->ctrlurb);
	usb_kill_urb(acm->ctrlurb);
bail_out:
bail_out:
	acm->used--;
	acm->used--;
	up(&open_sem);
	mutex_unlock(&open_mutex);
	return -EIO;
	return -EIO;
}
}


@@ -507,7 +508,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
	if (!acm || !acm->used)
	if (!acm || !acm->used)
		return;
		return;


	down(&open_sem);
	mutex_lock(&open_mutex);
	if (!--acm->used) {
	if (!--acm->used) {
		if (acm->dev) {
		if (acm->dev) {
			acm_set_control(acm, acm->ctrlout = 0);
			acm_set_control(acm, acm->ctrlout = 0);
@@ -518,7 +519,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
		} else
		} else
			acm_tty_unregister(acm);
			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)
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;
		return;
	}
	}


	down(&open_sem);
	mutex_lock(&open_mutex);
	if (!usb_get_intfdata(intf)) {
	if (!usb_get_intfdata(intf)) {
		up(&open_sem);
		mutex_unlock(&open_mutex);
		return;
		return;
	}
	}
	acm->dev = NULL;
	acm->dev = NULL;
@@ -1045,11 +1046,11 @@ static void acm_disconnect(struct usb_interface *intf)


	if (!acm->used) {
	if (!acm->used) {
		acm_tty_unregister(acm);
		acm_tty_unregister(acm);
		up(&open_sem);
		mutex_unlock(&open_mutex);
		return;
		return;
	}
	}


	up(&open_sem);
	mutex_unlock(&open_mutex);


	if (acm->tty)
	if (acm->tty)
		tty_hangup(acm->tty);
		tty_hangup(acm->tty);
+8 −7
Original line number Original line Diff line number Diff line
@@ -55,6 +55,7 @@
#include <linux/init.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/slab.h>
#include <linux/lp.h>
#include <linux/lp.h>
#include <linux/mutex.h>
#undef DEBUG
#undef DEBUG
#include <linux/usb.h>
#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 */
/* forward reference to make our lives easier */
static struct usb_driver usblp_driver;
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.
 * Functions for usblp control messages.
@@ -351,7 +352,7 @@ static int usblp_open(struct inode *inode, struct file *file)
	if (minor < 0)
	if (minor < 0)
		return -ENODEV;
		return -ENODEV;


	down (&usblp_sem);
	mutex_lock (&usblp_mutex);


	retval = -ENODEV;
	retval = -ENODEV;
	intf = usb_find_interface(&usblp_driver, minor);
	intf = usb_find_interface(&usblp_driver, minor);
@@ -399,7 +400,7 @@ static int usblp_open(struct inode *inode, struct file *file)
		}
		}
	}
	}
out:
out:
	up (&usblp_sem);
	mutex_unlock (&usblp_mutex);
	return retval;
	return retval;
}
}


@@ -425,13 +426,13 @@ static int usblp_release(struct inode *inode, struct file *file)
{
{
	struct usblp *usblp = file->private_data;
	struct usblp *usblp = file->private_data;


	down (&usblp_sem);
	mutex_lock (&usblp_mutex);
	usblp->used = 0;
	usblp->used = 0;
	if (usblp->present) {
	if (usblp->present) {
		usblp_unlink_urbs(usblp);
		usblp_unlink_urbs(usblp);
	} else 		/* finish cleanup from disconnect */
	} else 		/* finish cleanup from disconnect */
		usblp_cleanup (usblp);
		usblp_cleanup (usblp);
	up (&usblp_sem);
	mutex_unlock (&usblp_mutex);
	return 0;
	return 0;
}
}


@@ -1152,7 +1153,7 @@ static void usblp_disconnect(struct usb_interface *intf)


	device_remove_file(&intf->dev, &dev_attr_ieee1284_id);
	device_remove_file(&intf->dev, &dev_attr_ieee1284_id);


	down (&usblp_sem);
	mutex_lock (&usblp_mutex);
	down (&usblp->sem);
	down (&usblp->sem);
	usblp->present = 0;
	usblp->present = 0;
	usb_set_intfdata (intf, NULL);
	usb_set_intfdata (intf, NULL);
@@ -1166,7 +1167,7 @@ static void usblp_disconnect(struct usb_interface *intf)


	if (!usblp->used)
	if (!usblp->used)
		usblp_cleanup (usblp);
		usblp_cleanup (usblp);
	up (&usblp_sem);
	mutex_unlock (&usblp_mutex);
}
}


static struct usb_device_id usblp_ids [] = {
static struct usb_device_id usblp_ids [] = {
+4 −3
Original line number Original line Diff line number Diff line
@@ -57,6 +57,7 @@
#include <linux/usb.h>
#include <linux/usb.h>
#include <linux/smp_lock.h>
#include <linux/smp_lock.h>
#include <linux/usbdevice_fs.h>
#include <linux/usbdevice_fs.h>
#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <asm/uaccess.h>


#include "usb.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))
	if (!access_ok(VERIFY_WRITE, buf, nbytes))
		return -EFAULT;
		return -EFAULT;


	down (&usb_bus_list_lock);
	mutex_lock(&usb_bus_list_lock);
	/* print devices for all busses */
	/* print devices for all busses */
	list_for_each_entry(bus, &usb_bus_list, bus_list) {
	list_for_each_entry(bus, &usb_bus_list, bus_list) {
		/* recurse through all children of the root hub */
		/* 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);
		ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0);
		usb_unlock_device(bus->root_hub);
		usb_unlock_device(bus->root_hub);
		if (ret < 0) {
		if (ret < 0) {
			up(&usb_bus_list_lock);
			mutex_unlock(&usb_bus_list_lock);
			return ret;
			return ret;
		}
		}
		total_written += ret;
		total_written += ret;
	}
	}
	up (&usb_bus_list_lock);
	mutex_unlock(&usb_bus_list_lock);
	return total_written;
	return total_written;
}
}


+13 −12
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@
#include <asm/scatterlist.h>
#include <asm/scatterlist.h>
#include <linux/device.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/dma-mapping.h>
#include <linux/mutex.h>
#include <asm/irq.h>
#include <asm/irq.h>
#include <asm/byteorder.h>
#include <asm/byteorder.h>


@@ -93,7 +94,7 @@ struct usb_busmap {
static struct usb_busmap busmap;
static struct usb_busmap busmap;


/* used when updating list of hcds */
/* 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);
EXPORT_SYMBOL_GPL (usb_bus_list_lock);


/* used for controlling access to virtual root hubs */
/* used for controlling access to virtual root hubs */
@@ -761,14 +762,14 @@ static int usb_register_bus(struct usb_bus *bus)
{
{
	int busnum;
	int busnum;


	down (&usb_bus_list_lock);
	mutex_lock(&usb_bus_list_lock);
	busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1);
	busnum = find_next_zero_bit (busmap.busmap, USB_MAXBUS, 1);
	if (busnum < USB_MAXBUS) {
	if (busnum < USB_MAXBUS) {
		set_bit (busnum, busmap.busmap);
		set_bit (busnum, busmap.busmap);
		bus->busnum = busnum;
		bus->busnum = busnum;
	} else {
	} else {
		printk (KERN_ERR "%s: too many buses\n", usbcore_name);
		printk (KERN_ERR "%s: too many buses\n", usbcore_name);
		up(&usb_bus_list_lock);
		mutex_unlock(&usb_bus_list_lock);
		return -E2BIG;
		return -E2BIG;
	}
	}


@@ -776,7 +777,7 @@ static int usb_register_bus(struct usb_bus *bus)
					     bus->controller, "usb_host%d", busnum);
					     bus->controller, "usb_host%d", busnum);
	if (IS_ERR(bus->class_dev)) {
	if (IS_ERR(bus->class_dev)) {
		clear_bit(busnum, busmap.busmap);
		clear_bit(busnum, busmap.busmap);
		up(&usb_bus_list_lock);
		mutex_unlock(&usb_bus_list_lock);
		return PTR_ERR(bus->class_dev);
		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 */
	/* Add it to the local list of buses */
	list_add (&bus->bus_list, &usb_bus_list);
	list_add (&bus->bus_list, &usb_bus_list);
	up (&usb_bus_list_lock);
	mutex_unlock(&usb_bus_list_lock);


	usb_notify_add_bus(bus);
	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
	 * controller code, as well as having it call this when cleaning
	 * itself up
	 * itself up
	 */
	 */
	down (&usb_bus_list_lock);
	mutex_lock(&usb_bus_list_lock);
	list_del (&bus->bus_list);
	list_del (&bus->bus_list);
	up (&usb_bus_list_lock);
	mutex_unlock(&usb_bus_list_lock);


	usb_notify_remove_bus(bus);
	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);
	set_bit (devnum, usb_dev->bus->devmap.devicemap);
	usb_set_device_state(usb_dev, USB_STATE_ADDRESS);
	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->bus->root_hub = usb_dev;


	usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
	usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64);
	retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
	retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
	if (retval != sizeof usb_dev->descriptor) {
	if (retval != sizeof usb_dev->descriptor) {
		usb_dev->bus->root_hub = NULL;
		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",
		dev_dbg (parent_dev, "can't read %s device descriptor %d\n",
				usb_dev->dev.bus_id, retval);
				usb_dev->dev.bus_id, retval);
		return (retval < 0) ? retval : -EMSGSIZE;
		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",
		dev_err (parent_dev, "can't register root hub for %s, %d\n",
				usb_dev->dev.bus_id, retval);
				usb_dev->dev.bus_id, retval);
	}
	}
	up (&usb_bus_list_lock);
	mutex_unlock(&usb_bus_list_lock);


	if (retval == 0) {
	if (retval == 0) {
		spin_lock_irq (&hcd_root_hub_lock);
		spin_lock_irq (&hcd_root_hub_lock);
@@ -1891,9 +1892,9 @@ void usb_remove_hcd(struct usb_hcd *hcd)
	hcd->rh_registered = 0;
	hcd->rh_registered = 0;
	spin_unlock_irq (&hcd_root_hub_lock);
	spin_unlock_irq (&hcd_root_hub_lock);


	down(&usb_bus_list_lock);
	mutex_lock(&usb_bus_list_lock);
	usb_disconnect(&hcd->self.root_hub);
	usb_disconnect(&hcd->self.root_hub);
	up(&usb_bus_list_lock);
	mutex_unlock(&usb_bus_list_lock);


	hcd->poll_rh = 0;
	hcd->poll_rh = 0;
	del_timer_sync(&hcd->rh_timer);
	del_timer_sync(&hcd->rh_timer);
+1 −1
Original line number Original line Diff line number Diff line
@@ -364,7 +364,7 @@ extern void usb_set_device_state(struct usb_device *udev,
/* exported only within usbcore */
/* exported only within usbcore */


extern struct list_head usb_bus_list;
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 wait_queue_head_t usb_kill_urb_queue;


extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
Loading