[PATCH 22/46] USB: remove use of the bus rwsem, as it doesn't really protect anything.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>
Cc: Greg Kroah-Hartman <gregkh@...>, Alan Stern <stern@...>, Oliver Neukum <oneukum@...>, David Brownell <david-b@...>, linux-usb-devel <linux-usb-devel@...>
Date: Friday, April 27, 2007 - 2:53 pm

The driver core stopped using the rwsem a long time ago, yet the USB
core still grabbed the lock, thinking it protected something.  This
patch removes that useless use.

Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Oliver Neukum <oneukum@suse.de>
Cc: David Brownell <david-b@pacbell.net>
Cc: linux-usb-devel <linux-usb-devel@lists.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/usb/core/devices.c |    2 --
 drivers/usb/core/devio.c   |   13 -------------
 drivers/usb/core/driver.c  |   12 ++++++------
 drivers/usb/core/message.c |    2 +-
 4 files changed, 7 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index aefc798..6753ca0 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -246,7 +246,6 @@ static char *usb_dump_interface_descriptor(char *start, char *end,
 
 	if (start > end)
 		return start;
-	down_read(&usb_bus_type.subsys.rwsem);
 	if (iface) {
 		driver_name = (iface->dev.driver
 				? iface->dev.driver->name
@@ -263,7 +262,6 @@ static char *usb_dump_interface_descriptor(char *start, char *end,
 			 desc->bInterfaceSubClass,
 			 desc->bInterfaceProtocol,
 			 driver_name);
-	up_read(&usb_bus_type.subsys.rwsem);
 	return start;
 }
 
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 36e7a84..fc3545d 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -421,14 +421,11 @@ static int claimintf(struct dev_state *ps, unsigned int ifnum)
 	if (test_bit(ifnum, &ps->ifclaimed))
 		return 0;
 
-	/* lock against other changes to driver bindings */
-	down_write(&usb_bus_type.subsys.rwsem);
 	intf = usb_ifnum_to_if(dev, ifnum);
 	if (!intf)
 		err = -ENOENT;
 	else
 		err = usb_driver_claim_interface(&usbfs_driver, intf, ps);
-	up_write(&usb_bus_type.subsys.rwsem);
 	if (err == 0)
 		set_bit(ifnum, &ps->ifclaimed);
 	return err;
@@ -444,8 +441,6 @@ static int releaseintf(struct dev_state *ps, unsigned int ifnum)
 	if (ifnum >= 8*sizeof(ps->ifclaimed))
 		return err;
 	dev = ps->dev;
-	/* lock against other changes to driver bindings */
-	down_write(&usb_bus_type.subsys.rwsem);
 	intf = usb_ifnum_to_if(dev, ifnum);
 	if (!intf)
 		err = -ENOENT;
@@ -453,7 +448,6 @@ static int releaseintf(struct dev_state *ps, unsigned int ifnum)
 		usb_driver_release_interface(&usbfs_driver, intf);
 		err = 0;
 	}
-	up_write(&usb_bus_type.subsys.rwsem);
 	return err;
 }
 
@@ -813,7 +807,6 @@ static int proc_getdriver(struct dev_state *ps, void __user *arg)
 
 	if (copy_from_user(&gd, arg, sizeof(gd)))
 		return -EFAULT;
-	down_read(&usb_bus_type.subsys.rwsem);
 	intf = usb_ifnum_to_if(ps->dev, gd.interface);
 	if (!intf || !intf->dev.driver)
 		ret = -ENODATA;
@@ -822,7 +815,6 @@ static int proc_getdriver(struct dev_state *ps, void __user *arg)
 				sizeof(gd.driver));
 		ret = (copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0);
 	}
-	up_read(&usb_bus_type.subsys.rwsem);
 	return ret;
 }
 
@@ -1351,15 +1343,12 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
 
 	/* disconnect kernel driver from interface */
 	case USBDEVFS_DISCONNECT:
-
-		down_write(&usb_bus_type.subsys.rwsem);
 		if (intf->dev.driver) {
 			driver = to_usb_driver(intf->dev.driver);
 			dev_dbg (&intf->dev, "disconnect by usbfs\n");
 			usb_driver_release_interface(driver, intf);
 		} else
 			retval = -ENODATA;
-		up_write(&usb_bus_type.subsys.rwsem);
 		break;
 
 	/* let kernel drivers try to (re)bind to the interface */
@@ -1371,7 +1360,6 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
 
 	/* talk directly to the interface's driver */
 	default:
-		down_read(&usb_bus_type.subsys.rwsem);
 		if (intf->dev.driver)
 			driver = to_usb_driver(intf->dev.driver);
 		if (driver == NULL || driver->ioctl == NULL) {
@@ -1381,7 +1369,6 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
 			if (retval == -ENOIOCTLCMD)
 				retval = -ENOTTY;
 		}
-		up_read(&usb_bus_type.subsys.rwsem);
 	}
 
 	/* cleanup and return */
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 9e3e943..e6dd2b9 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -287,9 +287,9 @@ static int usb_unbind_interface(struct device *dev)
  * way to bind to an interface is to return the private data from
  * the driver's probe() method.
  *
- * Callers must own the device lock and the driver model's usb_bus_type.subsys
- * writelock.  So driver probe() entries don't need extra locking,
- * but other call contexts may need to explicitly claim those locks.
+ * Callers must own the device lock, so driver probe() entries don't need
+ * extra locking, but other call contexts may need to explicitly claim that
+ * lock.
  */
 int usb_driver_claim_interface(struct usb_driver *driver,
 				struct usb_interface *iface, void* priv)
@@ -330,9 +330,9 @@ EXPORT_SYMBOL(usb_driver_claim_interface);
  * also causes the driver disconnect() method to be called.
  *
  * This call is synchronous, and may not be used in an interrupt context.
- * Callers must own the device lock and the driver model's usb_bus_type.subsys
- * writelock.  So driver disconnect() entries don't need extra locking,
- * but other call contexts may need to explicitly claim those locks.
+ * Callers must own the device lock, so driver disconnect() entries don't
+ * need extra locking, but other call contexts may need to explicitly claim
+ * that lock.
  */
 void usb_driver_release_interface(struct usb_driver *driver,
 					struct usb_interface *iface)
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 217a3d6..c359ccb 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1349,7 +1349,7 @@ static void release_interface(struct device *dev)
  *
  * This call is synchronous. The calling context must be able to sleep,
  * must own the device lock, and must not hold the driver model's USB
- * bus rwsem; usb device driver probe() methods cannot use this routine.
+ * bus mutex; usb device driver probe() methods cannot use this routine.
  *
  * Returns zero on success, or else the status code returned by the
  * underlying call that failed.  On successful completion, each interface
-- 
1.5.1.2

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 13/46] Driver core: notify userspace of network devic..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 14/46] Driver core: suppress uevents via filter, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 15/46] Driver core: switch firmware_class to uevent_s..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 16/46] uevent: use add_uevent_var() instead of open c..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 17/46] Driver core: add suspend() and resume() to str..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 18/46] Kobject: kobject_uevent.c: Collapse unnecessar..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 19/46] kobject: kobject_add() reference leak, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 20/46] Driver core: remove use of rwsem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 21/46] SCSI: use the proper semaphore to protect the ..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 22/46] USB: remove use of the bus rwsem, as it doesn'..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 23/46] PNP: stop using the subsystem rwsem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 24/46] Input: serio - do not touch bus's rwsem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 25/46] Input: gameport - do not touch bus's rwsem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 26/46] IDE: remove rwsem use from ide-proc core, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 27/46] IEEE1394: remove rwsem use from ieee1394 core, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 28/46] PHY: remove rwsem use from phy core, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
Re: [PATCH 28/46] PHY: remove rwsem use from phy core, Andy Fleming, (Fri Apr 27, 5:11 pm)
[PATCH 29/46] qeth: Remove usage of subsys.rwsem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 30/46] kobject core: remove rwsem from struct subsystem, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 31/46] Driver core: make uevent-environment available..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 32/46] Driver core: warn when userspace writes to the..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 33/46] kobject: Comment and warning fixes to kobject.c, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 34/46] the overdue removal of the mount/umount uevents, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 35/46] debugfs: Add debugfs_create_u64(), Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 36/46] driver core: bus_add_driver should return an e..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 37/46] Driver core: use mutex instead of semaphore in..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 38/46] sysfs: bin.c printk fix, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 39/46] s390: cio: Delay uevents for subchannels, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 40/46] device_schedule_callback() needs a module refe..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 41/46] security: prevent permission checking of file ..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 42/46] define platform wakeup hook, use in pci_enable..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 43/46] s2ram: add arch irq disable/enable hooks, Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 44/46] mod_sysfs_setup() doesn't return errno when ko..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 45/46] drivers/base/attribute_container.c: use mutex ..., Greg Kroah-Hartman, (Fri Apr 27, 2:53 pm)
[PATCH 46/46] dev_dbg: check dev_dbg() arguments, Greg Kroah-Hartman, (Fri Apr 27, 2:54 pm)