aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2005-11-23 18:43:50 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-24 02:03:06 -0500
commit2b08c8d0468866f86da97f836c6ac14338cb81a9 (patch)
treeeca60a3b6811a825cd3642a666aa523a18fe484b
parent133747e8d1e912863edfb3869e36b97b9939d4fc (diff)
[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>
-rw-r--r--drivers/base/bus.c21
-rw-r--r--drivers/base/dd.c8
2 files changed, 12 insertions, 17 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 03204bfd17af..fa601b085eba 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -133,7 +133,7 @@ static struct kobj_type ktype_bus = {
133decl_subsys(bus, &ktype_bus, NULL); 133decl_subsys(bus, &ktype_bus, NULL);
134 134
135 135
136/* Manually detach a device from it's associated driver. */ 136/* Manually detach a device from its associated driver. */
137static int driver_helper(struct device *dev, void *data) 137static int driver_helper(struct device *dev, void *data)
138{ 138{
139 const char *name = data; 139 const char *name = data;
@@ -151,14 +151,13 @@ static ssize_t driver_unbind(struct device_driver *drv,
151 int err = -ENODEV; 151 int err = -ENODEV;
152 152
153 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); 153 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
154 if ((dev) && 154 if (dev && dev->driver == drv) {
155 (dev->driver == drv)) {
156 device_release_driver(dev); 155 device_release_driver(dev);
157 err = count; 156 err = count;
158 } 157 }
159 if (err) 158 put_device(dev);
160 return err; 159 put_bus(bus);
161 return count; 160 return err;
162} 161}
163static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); 162static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind);
164 163
@@ -175,16 +174,14 @@ static ssize_t driver_bind(struct device_driver *drv,
175 int err = -ENODEV; 174 int err = -ENODEV;
176 175
177 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper); 176 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
178 if ((dev) && 177 if (dev && dev->driver == NULL) {
179 (dev->driver == NULL)) {
180 down(&dev->sem); 178 down(&dev->sem);
181 err = driver_probe_device(drv, dev); 179 err = driver_probe_device(drv, dev);
182 up(&dev->sem); 180 up(&dev->sem);
183 put_device(dev);
184 } 181 }
185 if (err) 182 put_device(dev);
186 return err; 183 put_bus(bus);
187 return count; 184 return err;
188} 185}
189static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind); 186static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind);
190 187
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 3565e9795301..3b419c9a1e7e 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -62,7 +62,6 @@ void device_bind_driver(struct device * dev)
62 * because we don't know the format of the ID structures, nor what 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. 63 * is to be considered a match and what is not.
64 * 64 *
65 *
66 * This function returns 1 if a match is found, an error if one 65 * This function returns 1 if a match is found, an error if one
67 * occurs (that is not -ENODEV or -ENXIO), and 0 otherwise. 66 * occurs (that is not -ENODEV or -ENXIO), and 0 otherwise.
68 * 67 *
@@ -158,7 +157,6 @@ static int __driver_attach(struct device * dev, void * data)
158 driver_probe_device(drv, dev); 157 driver_probe_device(drv, dev);
159 up(&dev->sem); 158 up(&dev->sem);
160 159
161
162 return 0; 160 return 0;
163} 161}
164 162
@@ -225,15 +223,15 @@ void driver_detach(struct device_driver * drv)
225 struct device * dev; 223 struct device * dev;
226 224
227 for (;;) { 225 for (;;) {
228 spin_lock_irq(&drv->klist_devices.k_lock); 226 spin_lock(&drv->klist_devices.k_lock);
229 if (list_empty(&drv->klist_devices.k_list)) { 227 if (list_empty(&drv->klist_devices.k_list)) {
230 spin_unlock_irq(&drv->klist_devices.k_lock); 228 spin_unlock(&drv->klist_devices.k_lock);
231 break; 229 break;
232 } 230 }
233 dev = list_entry(drv->klist_devices.k_list.prev, 231 dev = list_entry(drv->klist_devices.k_list.prev,
234 struct device, knode_driver.n_node); 232 struct device, knode_driver.n_node);
235 get_device(dev); 233 get_device(dev);
236 spin_unlock_irq(&drv->klist_devices.k_lock); 234 spin_unlock(&drv->klist_devices.k_lock);
237 235
238 down(&dev->sem); 236 down(&dev->sem);
239 if (dev->driver == drv) 237 if (dev->driver == drv)