Commit 2b08c8d0 authored by Alan Stern's avatar Alan Stern Committed by Linus Torvalds

[PATCH] Small fixes to driver core

This patch (as603) makes a few small fixes to the driver core:

Change spin_lock_irq for a klist lock to spin_lock;

Fix reference count leaks;

Minor spelling and formatting changes.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Acked-by Patrick Mochel <mochel@digitalimplant.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 133747e8
...@@ -133,7 +133,7 @@ static struct kobj_type ktype_bus = { ...@@ -133,7 +133,7 @@ static struct kobj_type ktype_bus = {
decl_subsys(bus, &ktype_bus, NULL); decl_subsys(bus, &ktype_bus, NULL);
/* Manually detach a device from it's associated driver. */ /* Manually detach a device from its associated driver. */
static int driver_helper(struct device *dev, void *data) static int driver_helper(struct device *dev, void *data)
{ {
const char *name = data; const char *name = data;
...@@ -151,14 +151,13 @@ static ssize_t driver_unbind(struct device_driver *drv, ...@@ -151,14 +151,13 @@ static ssize_t driver_unbind(struct device_driver *drv,
int err = -ENODEV; int err = -ENODEV;
dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
if ((dev) && if (dev && dev->driver == drv) {
(dev->driver == drv)) {
device_release_driver(dev); device_release_driver(dev);
err = count; err = count;
} }
if (err) put_device(dev);
put_bus(bus);
return err; return err;
return count;
} }
static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind);
...@@ -175,16 +174,14 @@ static ssize_t driver_bind(struct device_driver *drv, ...@@ -175,16 +174,14 @@ static ssize_t driver_bind(struct device_driver *drv,
int err = -ENODEV; int err = -ENODEV;
dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
if ((dev) && if (dev && dev->driver == NULL) {
(dev->driver == NULL)) {
down(&dev->sem); down(&dev->sem);
err = driver_probe_device(drv, dev); err = driver_probe_device(drv, dev);
up(&dev->sem); up(&dev->sem);
put_device(dev);
} }
if (err) put_device(dev);
put_bus(bus);
return err; return err;
return count;
} }
static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind); static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind);
......
...@@ -62,7 +62,6 @@ void device_bind_driver(struct device * dev) ...@@ -62,7 +62,6 @@ void device_bind_driver(struct device * dev)
* because we don't know the format of the ID structures, nor what * because we don't know the format of the ID structures, nor what
* is to be considered a match and what is not. * is to be considered a match and what is not.
* *
*
* This function returns 1 if a match is found, an error if one * This function returns 1 if a match is found, an error if one
* occurs (that is not -ENODEV or -ENXIO), and 0 otherwise. * occurs (that is not -ENODEV or -ENXIO), and 0 otherwise.
* *
...@@ -158,7 +157,6 @@ static int __driver_attach(struct device * dev, void * data) ...@@ -158,7 +157,6 @@ static int __driver_attach(struct device * dev, void * data)
driver_probe_device(drv, dev); driver_probe_device(drv, dev);
up(&dev->sem); up(&dev->sem);
return 0; return 0;
} }
...@@ -225,15 +223,15 @@ void driver_detach(struct device_driver * drv) ...@@ -225,15 +223,15 @@ void driver_detach(struct device_driver * drv)
struct device * dev; struct device * dev;
for (;;) { for (;;) {
spin_lock_irq(&drv->klist_devices.k_lock); spin_lock(&drv->klist_devices.k_lock);
if (list_empty(&drv->klist_devices.k_list)) { if (list_empty(&drv->klist_devices.k_list)) {
spin_unlock_irq(&drv->klist_devices.k_lock); spin_unlock(&drv->klist_devices.k_lock);
break; break;
} }
dev = list_entry(drv->klist_devices.k_list.prev, dev = list_entry(drv->klist_devices.k_list.prev,
struct device, knode_driver.n_node); struct device, knode_driver.n_node);
get_device(dev); get_device(dev);
spin_unlock_irq(&drv->klist_devices.k_lock); spin_unlock(&drv->klist_devices.k_lock);
down(&dev->sem); down(&dev->sem);
if (dev->driver == drv) if (dev->driver == drv)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment