Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 16205
b: refs/heads/master
c: bf74ad5
h: refs/heads/master
i:
  16203: 1636749
v: v3
  • Loading branch information
Alan Stern authored and Greg Kroah-Hartman committed Jan 5, 2006
1 parent 8d0b8b1 commit 50fba7b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6d20b035dee4300e9786c6e1cb77a765c7f9460a
refs/heads/master: bf74ad5bc41727d5f2f1c6bedb2c1fac394de731
15 changes: 14 additions & 1 deletion trunk/drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,11 @@ static ssize_t driver_unbind(struct device_driver *drv,

dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
if (dev && dev->driver == drv) {
if (dev->parent) /* Needed for USB */
down(&dev->parent->sem);
device_release_driver(dev);
if (dev->parent)
up(&dev->parent->sem);
err = count;
}
put_device(dev);
Expand All @@ -175,9 +179,13 @@ static ssize_t driver_bind(struct device_driver *drv,

dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
if (dev && dev->driver == NULL) {
if (dev->parent) /* Needed for USB */
down(&dev->parent->sem);
down(&dev->sem);
err = driver_probe_device(drv, dev);
up(&dev->sem);
if (dev->parent)
up(&dev->parent->sem);
}
put_device(dev);
put_bus(bus);
Expand Down Expand Up @@ -484,8 +492,13 @@ void bus_remove_driver(struct device_driver * drv)
/* Helper for bus_rescan_devices's iter */
static int bus_rescan_devices_helper(struct device *dev, void *data)
{
if (!dev->driver)
if (!dev->driver) {
if (dev->parent) /* Needed for USB */
down(&dev->parent->sem);
device_attach(dev);
if (dev->parent)
up(&dev->parent->sem);
}
return 0;
}

Expand Down
15 changes: 14 additions & 1 deletion trunk/drivers/base/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void device_bind_driver(struct device * dev)
* This function returns 1 if a match is found, an error if one
* occurs (that is not -ENODEV or -ENXIO), and 0 otherwise.
*
* This function must be called with @dev->sem held.
* This function must be called with @dev->sem held. When called
* for a USB interface, @dev->parent->sem must be held as well.
*/
int driver_probe_device(struct device_driver * drv, struct device * dev)
{
Expand Down Expand Up @@ -123,6 +124,8 @@ static int __device_attach(struct device_driver * drv, void * data)
*
* Returns 1 if the device was bound to a driver;
* 0 if no matching device was found; error code otherwise.
*
* When called for a USB interface, @dev->parent->sem must be held.
*/
int device_attach(struct device * dev)
{
Expand Down Expand Up @@ -152,10 +155,14 @@ static int __driver_attach(struct device * dev, void * data)
* is an error.
*/

if (dev->parent) /* Needed for USB */
down(&dev->parent->sem);
down(&dev->sem);
if (!dev->driver)
driver_probe_device(drv, dev);
up(&dev->sem);
if (dev->parent)
up(&dev->parent->sem);

return 0;
}
Expand All @@ -181,6 +188,8 @@ void driver_attach(struct device_driver * drv)
* Manually detach device from driver.
*
* __device_release_driver() must be called with @dev->sem held.
* When called for a USB interface, @dev->parent->sem must be held
* as well.
*/

static void __device_release_driver(struct device * dev)
Expand Down Expand Up @@ -233,10 +242,14 @@ void driver_detach(struct device_driver * drv)
get_device(dev);
spin_unlock(&drv->klist_devices.k_lock);

if (dev->parent) /* Needed for USB */
down(&dev->parent->sem);
down(&dev->sem);
if (dev->driver == drv)
__device_release_driver(dev);
up(&dev->sem);
if (dev->parent)
up(&dev->parent->sem);
put_device(dev);
}
}
Expand Down

0 comments on commit 50fba7b

Please sign in to comment.