[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: Alan Stern <stern@rowland.harvard.edu>
Acked-by Patrick Mochel <mochel@digitalimplant.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by Alan Stern and committed by Linus Torvalds 2b08c8d0 133747e8

+12 -17
+9 -12
drivers/base/bus.c
··· 133 decl_subsys(bus, &ktype_bus, NULL); 134 135 136 - /* Manually detach a device from it's associated driver. */ 137 static int driver_helper(struct device *dev, void *data) 138 { 139 const char *name = data; ··· 151 int err = -ENODEV; 152 153 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); 154 - if ((dev) && 155 - (dev->driver == drv)) { 156 device_release_driver(dev); 157 err = count; 158 } 159 - if (err) 160 - return err; 161 - return count; 162 } 163 static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); 164 ··· 174 int err = -ENODEV; 175 176 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); 177 - if ((dev) && 178 - (dev->driver == NULL)) { 179 down(&dev->sem); 180 err = driver_probe_device(drv, dev); 181 up(&dev->sem); 182 - put_device(dev); 183 } 184 - if (err) 185 - return err; 186 - return count; 187 } 188 static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind); 189
··· 133 decl_subsys(bus, &ktype_bus, NULL); 134 135 136 + /* Manually detach a device from its associated driver. */ 137 static int driver_helper(struct device *dev, void *data) 138 { 139 const char *name = data; ··· 151 int err = -ENODEV; 152 153 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); 154 + if (dev && dev->driver == drv) { 155 device_release_driver(dev); 156 err = count; 157 } 158 + put_device(dev); 159 + put_bus(bus); 160 + return err; 161 } 162 static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); 163 ··· 175 int err = -ENODEV; 176 177 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); 178 + if (dev && dev->driver == NULL) { 179 down(&dev->sem); 180 err = driver_probe_device(drv, dev); 181 up(&dev->sem); 182 } 183 + put_device(dev); 184 + put_bus(bus); 185 + return err; 186 } 187 static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind); 188
+3 -5
drivers/base/dd.c
··· 62 * because we don't know the format of the ID structures, nor what 63 * is to be considered a match and what is not. 64 * 65 - * 66 * This function returns 1 if a match is found, an error if one 67 * occurs (that is not -ENODEV or -ENXIO), and 0 otherwise. 68 * ··· 157 driver_probe_device(drv, dev); 158 up(&dev->sem); 159 160 - 161 return 0; 162 } 163 ··· 223 struct device * dev; 224 225 for (;;) { 226 - spin_lock_irq(&drv->klist_devices.k_lock); 227 if (list_empty(&drv->klist_devices.k_list)) { 228 - spin_unlock_irq(&drv->klist_devices.k_lock); 229 break; 230 } 231 dev = list_entry(drv->klist_devices.k_list.prev, 232 struct device, knode_driver.n_node); 233 get_device(dev); 234 - spin_unlock_irq(&drv->klist_devices.k_lock); 235 236 down(&dev->sem); 237 if (dev->driver == drv)
··· 62 * because we don't know the format of the ID structures, nor what 63 * is to be considered a match and what is not. 64 * 65 * This function returns 1 if a match is found, an error if one 66 * occurs (that is not -ENODEV or -ENXIO), and 0 otherwise. 67 * ··· 158 driver_probe_device(drv, dev); 159 up(&dev->sem); 160 161 return 0; 162 } 163 ··· 225 struct device * dev; 226 227 for (;;) { 228 + spin_lock(&drv->klist_devices.k_lock); 229 if (list_empty(&drv->klist_devices.k_list)) { 230 + spin_unlock(&drv->klist_devices.k_lock); 231 break; 232 } 233 dev = list_entry(drv->klist_devices.k_list.prev, 234 struct device, knode_driver.n_node); 235 get_device(dev); 236 + spin_unlock(&drv->klist_devices.k_lock); 237 238 down(&dev->sem); 239 if (dev->driver == drv)