aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/amba/bus.c13
-rw-r--r--drivers/base/attribute_container.c26
-rw-r--r--drivers/base/base.h2
-rw-r--r--drivers/base/bus.c112
-rw-r--r--drivers/base/class.c2
-rw-r--r--drivers/base/core.c293
-rw-r--r--drivers/base/dd.c66
-rw-r--r--drivers/base/dmapool.c14
-rw-r--r--drivers/base/driver.c20
-rw-r--r--drivers/base/firmware_class.c10
-rw-r--r--drivers/base/power/main.c3
-rw-r--r--drivers/base/power/resume.c13
-rw-r--r--drivers/base/power/shutdown.c2
-rw-r--r--drivers/base/power/suspend.c12
-rw-r--r--drivers/ide/ide-proc.c4
-rw-r--r--drivers/ieee1394/nodemgr.c22
-rw-r--r--drivers/input/gameport/gameport.c39
-rw-r--r--drivers/input/serio/serio.c41
-rw-r--r--drivers/mmc/mmc_sysfs.c27
-rw-r--r--drivers/net/phy/fixed.c6
-rw-r--r--drivers/net/phy/phy_device.c9
-rw-r--r--drivers/pci/pci-driver.c6
-rw-r--r--drivers/pci/pci.c58
-rw-r--r--drivers/pnp/card.c6
-rw-r--r--drivers/s390/cio/device.c6
-rw-r--r--drivers/s390/crypto/ap_bus.c28
-rw-r--r--drivers/s390/net/qeth_proc.c2
-rw-r--r--drivers/scsi/hosts.c4
-rw-r--r--drivers/usb/core/devices.c2
-rw-r--r--drivers/usb/core/devio.c13
-rw-r--r--drivers/usb/core/driver.c12
-rw-r--r--drivers/usb/core/hub.c4
-rw-r--r--drivers/usb/core/message.c2
-rw-r--r--drivers/usb/host/ohci-hcd.c6
34 files changed, 512 insertions, 373 deletions
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index fd5475071acc..268e301775fc 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -47,14 +47,13 @@ static int amba_match(struct device *dev, struct device_driver *drv)
47static int amba_uevent(struct device *dev, char **envp, int nr_env, char *buf, int bufsz) 47static int amba_uevent(struct device *dev, char **envp, int nr_env, char *buf, int bufsz)
48{ 48{
49 struct amba_device *pcdev = to_amba_device(dev); 49 struct amba_device *pcdev = to_amba_device(dev);
50 int retval = 0, i = 0, len = 0;
50 51
51 if (nr_env < 2) 52 retval = add_uevent_var(envp, nr_env, &i,
52 return -ENOMEM; 53 buf, bufsz, &len,
53 54 "AMBA_ID=%08x", pcdev->periphid);
54 snprintf(buf, bufsz, "AMBA_ID=%08x", pcdev->periphid); 55 envp[i] = NULL;
55 *envp++ = buf; 56 return retval;
56 *envp++ = NULL;
57 return 0;
58} 57}
59#else 58#else
60#define amba_uevent NULL 59#define amba_uevent NULL
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index 22220733f76f..1ec0654665cf 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -62,7 +62,7 @@ EXPORT_SYMBOL_GPL(attribute_container_classdev_to_container);
62 62
63static struct list_head attribute_container_list; 63static struct list_head attribute_container_list;
64 64
65static DECLARE_MUTEX(attribute_container_mutex); 65static DEFINE_MUTEX(attribute_container_mutex);
66 66
67/** 67/**
68 * attribute_container_register - register an attribute container 68 * attribute_container_register - register an attribute container
@@ -77,9 +77,9 @@ attribute_container_register(struct attribute_container *cont)
77 klist_init(&cont->containers,internal_container_klist_get, 77 klist_init(&cont->containers,internal_container_klist_get,
78 internal_container_klist_put); 78 internal_container_klist_put);
79 79
80 down(&attribute_container_mutex); 80 mutex_lock(&attribute_container_mutex);
81 list_add_tail(&cont->node, &attribute_container_list); 81 list_add_tail(&cont->node, &attribute_container_list);
82 up(&attribute_container_mutex); 82 mutex_unlock(&attribute_container_mutex);
83 83
84 return 0; 84 return 0;
85} 85}
@@ -94,7 +94,7 @@ int
94attribute_container_unregister(struct attribute_container *cont) 94attribute_container_unregister(struct attribute_container *cont)
95{ 95{
96 int retval = -EBUSY; 96 int retval = -EBUSY;
97 down(&attribute_container_mutex); 97 mutex_lock(&attribute_container_mutex);
98 spin_lock(&cont->containers.k_lock); 98 spin_lock(&cont->containers.k_lock);
99 if (!list_empty(&cont->containers.k_list)) 99 if (!list_empty(&cont->containers.k_list))
100 goto out; 100 goto out;
@@ -102,7 +102,7 @@ attribute_container_unregister(struct attribute_container *cont)
102 list_del(&cont->node); 102 list_del(&cont->node);
103 out: 103 out:
104 spin_unlock(&cont->containers.k_lock); 104 spin_unlock(&cont->containers.k_lock);
105 up(&attribute_container_mutex); 105 mutex_unlock(&attribute_container_mutex);
106 return retval; 106 return retval;
107 107
108} 108}
@@ -145,7 +145,7 @@ attribute_container_add_device(struct device *dev,
145{ 145{
146 struct attribute_container *cont; 146 struct attribute_container *cont;
147 147
148 down(&attribute_container_mutex); 148 mutex_lock(&attribute_container_mutex);
149 list_for_each_entry(cont, &attribute_container_list, node) { 149 list_for_each_entry(cont, &attribute_container_list, node) {
150 struct internal_container *ic; 150 struct internal_container *ic;
151 151
@@ -173,7 +173,7 @@ attribute_container_add_device(struct device *dev,
173 attribute_container_add_class_device(&ic->classdev); 173 attribute_container_add_class_device(&ic->classdev);
174 klist_add_tail(&ic->node, &cont->containers); 174 klist_add_tail(&ic->node, &cont->containers);
175 } 175 }
176 up(&attribute_container_mutex); 176 mutex_unlock(&attribute_container_mutex);
177} 177}
178 178
179/* FIXME: can't break out of this unless klist_iter_exit is also 179/* FIXME: can't break out of this unless klist_iter_exit is also
@@ -211,7 +211,7 @@ attribute_container_remove_device(struct device *dev,
211{ 211{
212 struct attribute_container *cont; 212 struct attribute_container *cont;
213 213
214 down(&attribute_container_mutex); 214 mutex_lock(&attribute_container_mutex);
215 list_for_each_entry(cont, &attribute_container_list, node) { 215 list_for_each_entry(cont, &attribute_container_list, node) {
216 struct internal_container *ic; 216 struct internal_container *ic;
217 struct klist_iter iter; 217 struct klist_iter iter;
@@ -234,7 +234,7 @@ attribute_container_remove_device(struct device *dev,
234 } 234 }
235 } 235 }
236 } 236 }
237 up(&attribute_container_mutex); 237 mutex_unlock(&attribute_container_mutex);
238} 238}
239 239
240/** 240/**
@@ -255,7 +255,7 @@ attribute_container_device_trigger(struct device *dev,
255{ 255{
256 struct attribute_container *cont; 256 struct attribute_container *cont;
257 257
258 down(&attribute_container_mutex); 258 mutex_lock(&attribute_container_mutex);
259 list_for_each_entry(cont, &attribute_container_list, node) { 259 list_for_each_entry(cont, &attribute_container_list, node) {
260 struct internal_container *ic; 260 struct internal_container *ic;
261 struct klist_iter iter; 261 struct klist_iter iter;
@@ -273,7 +273,7 @@ attribute_container_device_trigger(struct device *dev,
273 fn(cont, dev, &ic->classdev); 273 fn(cont, dev, &ic->classdev);
274 } 274 }
275 } 275 }
276 up(&attribute_container_mutex); 276 mutex_unlock(&attribute_container_mutex);
277} 277}
278 278
279/** 279/**
@@ -295,12 +295,12 @@ attribute_container_trigger(struct device *dev,
295{ 295{
296 struct attribute_container *cont; 296 struct attribute_container *cont;
297 297
298 down(&attribute_container_mutex); 298 mutex_lock(&attribute_container_mutex);
299 list_for_each_entry(cont, &attribute_container_list, node) { 299 list_for_each_entry(cont, &attribute_container_list, node) {
300 if (cont->match(cont, dev)) 300 if (cont->match(cont, dev))
301 fn(cont, dev); 301 fn(cont, dev);
302 } 302 }
303 up(&attribute_container_mutex); 303 mutex_unlock(&attribute_container_mutex);
304} 304}
305 305
306/** 306/**
diff --git a/drivers/base/base.h b/drivers/base/base.h
index de7e1442ce60..d597f2659b23 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -16,7 +16,7 @@ extern int cpu_dev_init(void);
16extern int attribute_container_init(void); 16extern int attribute_container_init(void);
17 17
18extern int bus_add_device(struct device * dev); 18extern int bus_add_device(struct device * dev);
19extern int bus_attach_device(struct device * dev); 19extern void bus_attach_device(struct device * dev);
20extern void bus_remove_device(struct device * dev); 20extern void bus_remove_device(struct device * dev);
21extern struct bus_type *get_bus(struct bus_type * bus); 21extern struct bus_type *get_bus(struct bus_type * bus);
22extern void put_bus(struct bus_type * bus); 22extern void put_bus(struct bus_type * bus);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 253868e03c70..1d76e2349654 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -27,6 +27,9 @@
27#define to_driver(obj) container_of(obj, struct device_driver, kobj) 27#define to_driver(obj) container_of(obj, struct device_driver, kobj)
28 28
29 29
30static int __must_check bus_rescan_devices_helper(struct device *dev,
31 void *data);
32
30static ssize_t 33static ssize_t
31drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) 34drv_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
32{ 35{
@@ -60,8 +63,19 @@ static struct sysfs_ops driver_sysfs_ops = {
60 63
61static void driver_release(struct kobject * kobj) 64static void driver_release(struct kobject * kobj)
62{ 65{
63 struct device_driver * drv = to_driver(kobj); 66 /*
64 complete(&drv->unloaded); 67 * Yes this is an empty release function, it is this way because struct
68 * device is always a static object, not a dynamic one. Yes, this is
69 * not nice and bad, but remember, drivers are code, reference counted
70 * by the module count, not a device, which is really data. And yes,
71 * in the future I do want to have all drivers be created dynamically,
72 * and am working toward that goal, but it will take a bit longer...
73 *
74 * But do not let this example give _anyone_ the idea that they can
75 * create a release function without any code in it at all, to do that
76 * is almost always wrong. If you have any questions about this,
77 * please send an email to <greg@kroah.com>
78 */
65} 79}
66 80
67static struct kobj_type ktype_driver = { 81static struct kobj_type ktype_driver = {
@@ -133,7 +147,6 @@ static decl_subsys(bus, &ktype_bus, NULL);
133 147
134 148
135#ifdef CONFIG_HOTPLUG 149#ifdef CONFIG_HOTPLUG
136
137/* Manually detach a device from its associated driver. */ 150/* Manually detach a device from its associated driver. */
138static int driver_helper(struct device *dev, void *data) 151static int driver_helper(struct device *dev, void *data)
139{ 152{
@@ -199,6 +212,33 @@ static ssize_t driver_bind(struct device_driver *drv,
199} 212}
200static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind); 213static DRIVER_ATTR(bind, S_IWUSR, NULL, driver_bind);
201 214
215static ssize_t show_drivers_autoprobe(struct bus_type *bus, char *buf)
216{
217 return sprintf(buf, "%d\n", bus->drivers_autoprobe);
218}
219
220static ssize_t store_drivers_autoprobe(struct bus_type *bus,
221 const char *buf, size_t count)
222{
223 if (buf[0] == '0')
224 bus->drivers_autoprobe = 0;
225 else
226 bus->drivers_autoprobe = 1;
227 return count;
228}
229
230static ssize_t store_drivers_probe(struct bus_type *bus,
231 const char *buf, size_t count)
232{
233 struct device *dev;
234
235 dev = bus_find_device(bus, NULL, (void *)buf, driver_helper);
236 if (!dev)
237 return -ENODEV;
238 if (bus_rescan_devices_helper(dev, NULL) != 0)
239 return -EINVAL;
240 return count;
241}
202#endif 242#endif
203 243
204static struct device * next_device(struct klist_iter * i) 244static struct device * next_device(struct klist_iter * i)
@@ -418,21 +458,21 @@ out_put:
418 * - Add device to bus's list of devices. 458 * - Add device to bus's list of devices.
419 * - Try to attach to driver. 459 * - Try to attach to driver.
420 */ 460 */
421int bus_attach_device(struct device * dev) 461void bus_attach_device(struct device * dev)
422{ 462{
423 struct bus_type *bus = dev->bus; 463 struct bus_type *bus = dev->bus;
424 int ret = 0; 464 int ret = 0;
425 465
426 if (bus) { 466 if (bus) {
427 dev->is_registered = 1; 467 dev->is_registered = 1;
428 ret = device_attach(dev); 468 if (bus->drivers_autoprobe)
429 if (ret >= 0) { 469 ret = device_attach(dev);
470 WARN_ON(ret < 0);
471 if (ret >= 0)
430 klist_add_tail(&dev->knode_bus, &bus->klist_devices); 472 klist_add_tail(&dev->knode_bus, &bus->klist_devices);
431 ret = 0; 473 else
432 } else
433 dev->is_registered = 0; 474 dev->is_registered = 0;
434 } 475 }
435 return ret;
436} 476}
437 477
438/** 478/**
@@ -515,9 +555,41 @@ static void remove_bind_files(struct device_driver *drv)
515 driver_remove_file(drv, &driver_attr_bind); 555 driver_remove_file(drv, &driver_attr_bind);
516 driver_remove_file(drv, &driver_attr_unbind); 556 driver_remove_file(drv, &driver_attr_unbind);
517} 557}
558
559static int add_probe_files(struct bus_type *bus)
560{
561 int retval;
562
563 bus->drivers_probe_attr.attr.name = "drivers_probe";
564 bus->drivers_probe_attr.attr.mode = S_IWUSR;
565 bus->drivers_probe_attr.attr.owner = bus->owner;
566 bus->drivers_probe_attr.store = store_drivers_probe;
567 retval = bus_create_file(bus, &bus->drivers_probe_attr);
568 if (retval)
569 goto out;
570
571 bus->drivers_autoprobe_attr.attr.name = "drivers_autoprobe";
572 bus->drivers_autoprobe_attr.attr.mode = S_IWUSR | S_IRUGO;
573 bus->drivers_autoprobe_attr.attr.owner = bus->owner;
574 bus->drivers_autoprobe_attr.show = show_drivers_autoprobe;
575 bus->drivers_autoprobe_attr.store = store_drivers_autoprobe;
576 retval = bus_create_file(bus, &bus->drivers_autoprobe_attr);
577 if (retval)
578 bus_remove_file(bus, &bus->drivers_probe_attr);
579out:
580 return retval;
581}
582
583static void remove_probe_files(struct bus_type *bus)
584{
585 bus_remove_file(bus, &bus->drivers_autoprobe_attr);
586 bus_remove_file(bus, &bus->drivers_probe_attr);
587}
518#else 588#else
519static inline int add_bind_files(struct device_driver *drv) { return 0; } 589static inline int add_bind_files(struct device_driver *drv) { return 0; }
520static inline void remove_bind_files(struct device_driver *drv) {} 590static inline void remove_bind_files(struct device_driver *drv) {}
591static inline int add_probe_files(struct bus_type *bus) { return 0; }
592static inline void remove_probe_files(struct bus_type *bus) {}
521#endif 593#endif
522 594
523/** 595/**
@@ -531,7 +603,7 @@ int bus_add_driver(struct device_driver *drv)
531 int error = 0; 603 int error = 0;
532 604
533 if (!bus) 605 if (!bus)
534 return 0; 606 return -EINVAL;
535 607
536 pr_debug("bus %s: add driver %s\n", bus->name, drv->name); 608 pr_debug("bus %s: add driver %s\n", bus->name, drv->name);
537 error = kobject_set_name(&drv->kobj, "%s", drv->name); 609 error = kobject_set_name(&drv->kobj, "%s", drv->name);
@@ -541,9 +613,11 @@ int bus_add_driver(struct device_driver *drv)
541 if ((error = kobject_register(&drv->kobj))) 613 if ((error = kobject_register(&drv->kobj)))
542 goto out_put_bus; 614 goto out_put_bus;
543 615
544 error = driver_attach(drv); 616 if (drv->bus->drivers_autoprobe) {
545 if (error) 617 error = driver_attach(drv);
546 goto out_unregister; 618 if (error)
619 goto out_unregister;
620 }
547 klist_add_tail(&drv->knode_bus, &bus->klist_drivers); 621 klist_add_tail(&drv->knode_bus, &bus->klist_drivers);
548 module_add_driver(drv->owner, drv); 622 module_add_driver(drv->owner, drv);
549 623
@@ -605,8 +679,6 @@ static int __must_check bus_rescan_devices_helper(struct device *dev,
605 ret = device_attach(dev); 679 ret = device_attach(dev);
606 if (dev->parent) 680 if (dev->parent)
607 up(&dev->parent->sem); 681 up(&dev->parent->sem);
608 if (ret > 0)
609 ret = 0;
610 } 682 }
611 return ret < 0 ? ret : 0; 683 return ret < 0 ? ret : 0;
612} 684}
@@ -762,6 +834,12 @@ int bus_register(struct bus_type * bus)
762 834
763 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); 835 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put);
764 klist_init(&bus->klist_drivers, NULL, NULL); 836 klist_init(&bus->klist_drivers, NULL, NULL);
837
838 bus->drivers_autoprobe = 1;
839 retval = add_probe_files(bus);
840 if (retval)
841 goto bus_probe_files_fail;
842
765 retval = bus_add_attrs(bus); 843 retval = bus_add_attrs(bus);
766 if (retval) 844 if (retval)
767 goto bus_attrs_fail; 845 goto bus_attrs_fail;
@@ -770,6 +848,8 @@ int bus_register(struct bus_type * bus)
770 return 0; 848 return 0;
771 849
772bus_attrs_fail: 850bus_attrs_fail:
851 remove_probe_files(bus);
852bus_probe_files_fail:
773 kset_unregister(&bus->drivers); 853 kset_unregister(&bus->drivers);
774bus_drivers_fail: 854bus_drivers_fail:
775 kset_unregister(&bus->devices); 855 kset_unregister(&bus->devices);
@@ -779,7 +859,6 @@ out:
779 return retval; 859 return retval;
780} 860}
781 861
782
783/** 862/**
784 * bus_unregister - remove a bus from the system 863 * bus_unregister - remove a bus from the system
785 * @bus: bus. 864 * @bus: bus.
@@ -791,6 +870,7 @@ void bus_unregister(struct bus_type * bus)
791{ 870{
792 pr_debug("bus %s: unregistering\n", bus->name); 871 pr_debug("bus %s: unregistering\n", bus->name);
793 bus_remove_attrs(bus); 872 bus_remove_attrs(bus);
873 remove_probe_files(bus);
794 kset_unregister(&bus->drivers); 874 kset_unregister(&bus->drivers);
795 kset_unregister(&bus->devices); 875 kset_unregister(&bus->devices);
796 subsystem_unregister(&bus->subsys); 876 subsystem_unregister(&bus->subsys);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index d5968128be2b..80bbb2074636 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -145,6 +145,7 @@ int class_register(struct class * cls)
145 INIT_LIST_HEAD(&cls->children); 145 INIT_LIST_HEAD(&cls->children);
146 INIT_LIST_HEAD(&cls->devices); 146 INIT_LIST_HEAD(&cls->devices);
147 INIT_LIST_HEAD(&cls->interfaces); 147 INIT_LIST_HEAD(&cls->interfaces);
148 kset_init(&cls->class_dirs);
148 init_MUTEX(&cls->sem); 149 init_MUTEX(&cls->sem);
149 error = kobject_set_name(&cls->subsys.kset.kobj, "%s", cls->name); 150 error = kobject_set_name(&cls->subsys.kset.kobj, "%s", cls->name);
150 if (error) 151 if (error)
@@ -163,7 +164,6 @@ int class_register(struct class * cls)
163void class_unregister(struct class * cls) 164void class_unregister(struct class * cls)
164{ 165{
165 pr_debug("device class '%s': unregistering\n", cls->name); 166 pr_debug("device class '%s': unregistering\n", cls->name);
166 kobject_unregister(cls->virtual_dir);
167 remove_class_attrs(cls); 167 remove_class_attrs(cls);
168 subsystem_unregister(&cls->subsys); 168 subsystem_unregister(&cls->subsys);
169} 169}
diff --git a/drivers/base/core.c b/drivers/base/core.c
index d7fcf823a42a..8aa090da1cd7 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -43,7 +43,8 @@ int (*platform_notify_remove)(struct device * dev) = NULL;
43const char *dev_driver_string(struct device *dev) 43const char *dev_driver_string(struct device *dev)
44{ 44{
45 return dev->driver ? dev->driver->name : 45 return dev->driver ? dev->driver->name :
46 (dev->bus ? dev->bus->name : ""); 46 (dev->bus ? dev->bus->name :
47 (dev->class ? dev->class->name : ""));
47} 48}
48EXPORT_SYMBOL(dev_driver_string); 49EXPORT_SYMBOL(dev_driver_string);
49 50
@@ -119,6 +120,8 @@ static int dev_uevent_filter(struct kset *kset, struct kobject *kobj)
119 120
120 if (ktype == &ktype_device) { 121 if (ktype == &ktype_device) {
121 struct device *dev = to_dev(kobj); 122 struct device *dev = to_dev(kobj);
123 if (dev->uevent_suppress)
124 return 0;
122 if (dev->bus) 125 if (dev->bus)
123 return 1; 126 return 1;
124 if (dev->class) 127 if (dev->class)
@@ -156,6 +159,11 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp,
156 "MINOR=%u", MINOR(dev->devt)); 159 "MINOR=%u", MINOR(dev->devt));
157 } 160 }
158 161
162 if (dev->type && dev->type->name)
163 add_uevent_var(envp, num_envp, &i,
164 buffer, buffer_size, &length,
165 "DEVTYPE=%s", dev->type->name);
166
159 if (dev->driver) 167 if (dev->driver)
160 add_uevent_var(envp, num_envp, &i, 168 add_uevent_var(envp, num_envp, &i,
161 buffer, buffer_size, &length, 169 buffer, buffer_size, &length,
@@ -238,71 +246,152 @@ static struct kset_uevent_ops device_uevent_ops = {
238 .uevent = dev_uevent, 246 .uevent = dev_uevent,
239}; 247};
240 248
249static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
250 char *buf)
251{
252 struct kobject *top_kobj;
253 struct kset *kset;
254 char *envp[32];
255 char data[PAGE_SIZE];
256 char *pos;
257 int i;
258 size_t count = 0;
259 int retval;
260
261 /* search the kset, the device belongs to */
262 top_kobj = &dev->kobj;
263 if (!top_kobj->kset && top_kobj->parent) {
264 do {
265 top_kobj = top_kobj->parent;
266 } while (!top_kobj->kset && top_kobj->parent);
267 }
268 if (!top_kobj->kset)
269 goto out;
270 kset = top_kobj->kset;
271 if (!kset->uevent_ops || !kset->uevent_ops->uevent)
272 goto out;
273
274 /* respect filter */
275 if (kset->uevent_ops && kset->uevent_ops->filter)
276 if (!kset->uevent_ops->filter(kset, &dev->kobj))
277 goto out;
278
279 /* let the kset specific function add its keys */
280 pos = data;
281 retval = kset->uevent_ops->uevent(kset, &dev->kobj,
282 envp, ARRAY_SIZE(envp),
283 pos, PAGE_SIZE);
284 if (retval)
285 goto out;
286
287 /* copy keys to file */
288 for (i = 0; envp[i]; i++) {
289 pos = &buf[count];
290 count += sprintf(pos, "%s\n", envp[i]);
291 }
292out:
293 return count;
294}
295
241static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, 296static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
242 const char *buf, size_t count) 297 const char *buf, size_t count)
243{ 298{
299 if (memcmp(buf, "add", 3) != 0)
300 dev_err(dev, "uevent: unsupported action-string; this will "
301 "be ignored in a future kernel version");
244 kobject_uevent(&dev->kobj, KOBJ_ADD); 302 kobject_uevent(&dev->kobj, KOBJ_ADD);
245 return count; 303 return count;
246} 304}
247 305
248static int device_add_groups(struct device *dev) 306static int device_add_attributes(struct device *dev,
307 struct device_attribute *attrs)
308{
309 int error = 0;
310 int i;
311
312 if (attrs) {
313 for (i = 0; attr_name(attrs[i]); i++) {
314 error = device_create_file(dev, &attrs[i]);
315 if (error)
316 break;
317 }
318 if (error)
319 while (--i >= 0)
320 device_remove_file(dev, &attrs[i]);
321 }
322 return error;
323}
324
325static void device_remove_attributes(struct device *dev,
326 struct device_attribute *attrs)
249{ 327{
250 int i; 328 int i;
329
330 if (attrs)
331 for (i = 0; attr_name(attrs[i]); i++)
332 device_remove_file(dev, &attrs[i]);
333}
334
335static int device_add_groups(struct device *dev,
336 struct attribute_group **groups)
337{
251 int error = 0; 338 int error = 0;
339 int i;
252 340
253 if (dev->groups) { 341 if (groups) {
254 for (i = 0; dev->groups[i]; i++) { 342 for (i = 0; groups[i]; i++) {
255 error = sysfs_create_group(&dev->kobj, dev->groups[i]); 343 error = sysfs_create_group(&dev->kobj, groups[i]);
256 if (error) { 344 if (error) {
257 while (--i >= 0) 345 while (--i >= 0)
258 sysfs_remove_group(&dev->kobj, dev->groups[i]); 346 sysfs_remove_group(&dev->kobj, groups[i]);
259 goto out; 347 break;
260 } 348 }
261 } 349 }
262 } 350 }
263out:
264 return error; 351 return error;
265} 352}
266 353
267static void device_remove_groups(struct device *dev) 354static void device_remove_groups(struct device *dev,
355 struct attribute_group **groups)
268{ 356{
269 int i; 357 int i;
270 if (dev->groups) { 358
271 for (i = 0; dev->groups[i]; i++) { 359 if (groups)
272 sysfs_remove_group(&dev->kobj, dev->groups[i]); 360 for (i = 0; groups[i]; i++)
273 } 361 sysfs_remove_group(&dev->kobj, groups[i]);
274 }
275} 362}
276 363
277static int device_add_attrs(struct device *dev) 364static int device_add_attrs(struct device *dev)
278{ 365{
279 struct class *class = dev->class; 366 struct class *class = dev->class;
280 struct device_type *type = dev->type; 367 struct device_type *type = dev->type;
281 int error = 0; 368 int error;
282 int i;
283 369
284 if (class && class->dev_attrs) { 370 if (class) {
285 for (i = 0; attr_name(class->dev_attrs[i]); i++) { 371 error = device_add_attributes(dev, class->dev_attrs);
286 error = device_create_file(dev, &class->dev_attrs[i]);
287 if (error)
288 break;
289 }
290 if (error) 372 if (error)
291 while (--i >= 0) 373 return error;
292 device_remove_file(dev, &class->dev_attrs[i]);
293 } 374 }
294 375
295 if (type && type->attrs) { 376 if (type) {
296 for (i = 0; attr_name(type->attrs[i]); i++) { 377 error = device_add_groups(dev, type->groups);
297 error = device_create_file(dev, &type->attrs[i]);
298 if (error)
299 break;
300 }
301 if (error) 378 if (error)
302 while (--i >= 0) 379 goto err_remove_class_attrs;
303 device_remove_file(dev, &type->attrs[i]);
304 } 380 }
305 381
382 error = device_add_groups(dev, dev->groups);
383 if (error)
384 goto err_remove_type_groups;
385
386 return 0;
387
388 err_remove_type_groups:
389 if (type)
390 device_remove_groups(dev, type->groups);
391 err_remove_class_attrs:
392 if (class)
393 device_remove_attributes(dev, class->dev_attrs);
394
306 return error; 395 return error;
307} 396}
308 397
@@ -310,17 +399,14 @@ static void device_remove_attrs(struct device *dev)
310{ 399{
311 struct class *class = dev->class; 400 struct class *class = dev->class;
312 struct device_type *type = dev->type; 401 struct device_type *type = dev->type;
313 int i;
314 402
315 if (class && class->dev_attrs) { 403 device_remove_groups(dev, dev->groups);
316 for (i = 0; attr_name(class->dev_attrs[i]); i++)
317 device_remove_file(dev, &class->dev_attrs[i]);
318 }
319 404
320 if (type && type->attrs) { 405 if (type)
321 for (i = 0; attr_name(type->attrs[i]); i++) 406 device_remove_groups(dev, type->groups);
322 device_remove_file(dev, &type->attrs[i]); 407
323 } 408 if (class)
409 device_remove_attributes(dev, class->dev_attrs);
324} 410}
325 411
326 412
@@ -394,9 +480,10 @@ void device_remove_bin_file(struct device *dev, struct bin_attribute *attr)
394EXPORT_SYMBOL_GPL(device_remove_bin_file); 480EXPORT_SYMBOL_GPL(device_remove_bin_file);
395 481
396/** 482/**
397 * device_schedule_callback - helper to schedule a callback for a device 483 * device_schedule_callback_owner - helper to schedule a callback for a device
398 * @dev: device. 484 * @dev: device.
399 * @func: callback function to invoke later. 485 * @func: callback function to invoke later.
486 * @owner: module owning the callback routine
400 * 487 *
401 * Attribute methods must not unregister themselves or their parent device 488 * Attribute methods must not unregister themselves or their parent device
402 * (which would amount to the same thing). Attempts to do so will deadlock, 489 * (which would amount to the same thing). Attempts to do so will deadlock,
@@ -407,20 +494,23 @@ EXPORT_SYMBOL_GPL(device_remove_bin_file);
407 * argument in the workqueue's process context. @dev will be pinned until 494 * argument in the workqueue's process context. @dev will be pinned until
408 * @func returns. 495 * @func returns.
409 * 496 *
497 * This routine is usually called via the inline device_schedule_callback(),
498 * which automatically sets @owner to THIS_MODULE.
499 *
410 * Returns 0 if the request was submitted, -ENOMEM if storage could not 500 * Returns 0 if the request was submitted, -ENOMEM if storage could not
411 * be allocated. 501 * be allocated, -ENODEV if a reference to @owner isn't available.
412 * 502 *
413 * NOTE: This routine won't work if CONFIG_SYSFS isn't set! It uses an 503 * NOTE: This routine won't work if CONFIG_SYSFS isn't set! It uses an
414 * underlying sysfs routine (since it is intended for use by attribute 504 * underlying sysfs routine (since it is intended for use by attribute
415 * methods), and if sysfs isn't available you'll get nothing but -ENOSYS. 505 * methods), and if sysfs isn't available you'll get nothing but -ENOSYS.
416 */ 506 */
417int device_schedule_callback(struct device *dev, 507int device_schedule_callback_owner(struct device *dev,
418 void (*func)(struct device *)) 508 void (*func)(struct device *), struct module *owner)
419{ 509{
420 return sysfs_schedule_callback(&dev->kobj, 510 return sysfs_schedule_callback(&dev->kobj,
421 (void (*)(void *)) func, dev); 511 (void (*)(void *)) func, dev, owner);
422} 512}
423EXPORT_SYMBOL_GPL(device_schedule_callback); 513EXPORT_SYMBOL_GPL(device_schedule_callback_owner);
424 514
425static void klist_children_get(struct klist_node *n) 515static void klist_children_get(struct klist_node *n)
426{ 516{
@@ -477,34 +567,58 @@ static struct kobject * get_device_parent(struct device *dev,
477 return NULL; 567 return NULL;
478} 568}
479#else 569#else
480static struct kobject * virtual_device_parent(struct device *dev) 570static struct kobject *virtual_device_parent(struct device *dev)
481{ 571{
482 if (!dev->class) 572 static struct kobject *virtual_dir = NULL;
483 return ERR_PTR(-ENODEV);
484 573
485 if (!dev->class->virtual_dir) { 574 if (!virtual_dir)
486 static struct kobject *virtual_dir = NULL; 575 virtual_dir = kobject_add_dir(&devices_subsys.kset.kobj, "virtual");
487 576
488 if (!virtual_dir) 577 return virtual_dir;
489 virtual_dir = kobject_add_dir(&devices_subsys.kset.kobj, "virtual");
490 dev->class->virtual_dir = kobject_add_dir(virtual_dir, dev->class->name);
491 }
492
493 return dev->class->virtual_dir;
494} 578}
495 579
496static struct kobject * get_device_parent(struct device *dev, 580static struct kobject * get_device_parent(struct device *dev,
497 struct device *parent) 581 struct device *parent)
498{ 582{
499 /* if this is a class device, and has no parent, create one */ 583 if (dev->class) {
500 if ((dev->class) && (parent == NULL)) { 584 struct kobject *kobj = NULL;
501 return virtual_device_parent(dev); 585 struct kobject *parent_kobj;
502 } else if (parent) 586 struct kobject *k;
587
588 /*
589 * If we have no parent, we live in "virtual".
590 * Class-devices with a bus-device as parent, live
591 * in a class-directory to prevent namespace collisions.
592 */
593 if (parent == NULL)
594 parent_kobj = virtual_device_parent(dev);
595 else if (parent->class)
596 return &parent->kobj;
597 else
598 parent_kobj = &parent->kobj;
599
600 /* find our class-directory at the parent and reference it */
601 spin_lock(&dev->class->class_dirs.list_lock);
602 list_for_each_entry(k, &dev->class->class_dirs.list, entry)
603 if (k->parent == parent_kobj) {
604 kobj = kobject_get(k);
605 break;
606 }
607 spin_unlock(&dev->class->class_dirs.list_lock);
608 if (kobj)
609 return kobj;
610
611 /* or create a new class-directory at the parent device */
612 return kobject_kset_add_dir(&dev->class->class_dirs,
613 parent_kobj, dev->class->name);
614 }
615
616 if (parent)
503 return &parent->kobj; 617 return &parent->kobj;
504 return NULL; 618 return NULL;
505} 619}
506
507#endif 620#endif
621
508static int setup_parent(struct device *dev, struct device *parent) 622static int setup_parent(struct device *dev, struct device *parent)
509{ 623{
510 struct kobject *kobj; 624 struct kobject *kobj;
@@ -541,7 +655,6 @@ int device_add(struct device *dev)
541 pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); 655 pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id);
542 656
543 parent = get_device(dev->parent); 657 parent = get_device(dev->parent);
544
545 error = setup_parent(dev, parent); 658 error = setup_parent(dev, parent);
546 if (error) 659 if (error)
547 goto Error; 660 goto Error;
@@ -562,10 +675,11 @@ int device_add(struct device *dev)
562 BUS_NOTIFY_ADD_DEVICE, dev); 675 BUS_NOTIFY_ADD_DEVICE, dev);
563 676
564 dev->uevent_attr.attr.name = "uevent"; 677 dev->uevent_attr.attr.name = "uevent";
565 dev->uevent_attr.attr.mode = S_IWUSR; 678 dev->uevent_attr.attr.mode = S_IRUGO | S_IWUSR;
566 if (dev->driver) 679 if (dev->driver)
567 dev->uevent_attr.attr.owner = dev->driver->owner; 680 dev->uevent_attr.attr.owner = dev->driver->owner;
568 dev->uevent_attr.store = store_uevent; 681 dev->uevent_attr.store = store_uevent;
682 dev->uevent_attr.show = show_uevent;
569 error = device_create_file(dev, &dev->uevent_attr); 683 error = device_create_file(dev, &dev->uevent_attr);
570 if (error) 684 if (error)
571 goto attrError; 685 goto attrError;
@@ -614,16 +728,12 @@ int device_add(struct device *dev)
614 728
615 if ((error = device_add_attrs(dev))) 729 if ((error = device_add_attrs(dev)))
616 goto AttrsError; 730 goto AttrsError;
617 if ((error = device_add_groups(dev)))
618 goto GroupError;
619 if ((error = device_pm_add(dev))) 731 if ((error = device_pm_add(dev)))
620 goto PMError; 732 goto PMError;
621 if ((error = bus_add_device(dev))) 733 if ((error = bus_add_device(dev)))
622 goto BusError; 734 goto BusError;
623 if (!dev->uevent_suppress) 735 kobject_uevent(&dev->kobj, KOBJ_ADD);
624 kobject_uevent(&dev->kobj, KOBJ_ADD); 736 bus_attach_device(dev);
625 if ((error = bus_attach_device(dev)))
626 goto AttachError;
627 if (parent) 737 if (parent)
628 klist_add_tail(&dev->knode_parent, &parent->klist_children); 738 klist_add_tail(&dev->knode_parent, &parent->klist_children);
629 739
@@ -639,19 +749,15 @@ int device_add(struct device *dev)
639 up(&dev->class->sem); 749 up(&dev->class->sem);
640 } 750 }
641 Done: 751 Done:
642 kfree(class_name); 752 kfree(class_name);
643 put_device(dev); 753 put_device(dev);
644 return error; 754 return error;
645 AttachError:
646 bus_remove_device(dev);
647 BusError: 755 BusError:
648 device_pm_remove(dev); 756 device_pm_remove(dev);
649 PMError: 757 PMError:
650 if (dev->bus) 758 if (dev->bus)
651 blocking_notifier_call_chain(&dev->bus->bus_notifier, 759 blocking_notifier_call_chain(&dev->bus->bus_notifier,
652 BUS_NOTIFY_DEL_DEVICE, dev); 760 BUS_NOTIFY_DEL_DEVICE, dev);
653 device_remove_groups(dev);
654 GroupError:
655 device_remove_attrs(dev); 761 device_remove_attrs(dev);
656 AttrsError: 762 AttrsError:
657 if (dev->devt_attr) { 763 if (dev->devt_attr) {
@@ -677,15 +783,6 @@ int device_add(struct device *dev)
677#endif 783#endif
678 sysfs_remove_link(&dev->kobj, "device"); 784 sysfs_remove_link(&dev->kobj, "device");
679 } 785 }
680
681 down(&dev->class->sem);
682 /* notify any interfaces that the device is now gone */
683 list_for_each_entry(class_intf, &dev->class->interfaces, node)
684 if (class_intf->remove_dev)
685 class_intf->remove_dev(dev, class_intf);
686 /* remove the device from the class list */
687 list_del_init(&dev->node);
688 up(&dev->class->sem);
689 } 786 }
690 ueventattrError: 787 ueventattrError:
691 device_remove_file(dev, &dev->uevent_attr); 788 device_remove_file(dev, &dev->uevent_attr);
@@ -796,9 +893,33 @@ void device_del(struct device * dev)
796 /* remove the device from the class list */ 893 /* remove the device from the class list */
797 list_del_init(&dev->node); 894 list_del_init(&dev->node);
798 up(&dev->class->sem); 895 up(&dev->class->sem);
896
897 /* If we live in a parent class-directory, unreference it */
898 if (dev->kobj.parent->kset == &dev->class->class_dirs) {
899 struct device *d;
900 int other = 0;
901
902 /*
903 * if we are the last child of our class, delete
904 * our class-directory at this parent
905 */
906 down(&dev->class->sem);
907 list_for_each_entry(d, &dev->class->devices, node) {
908 if (d == dev)
909 continue;
910 if (d->kobj.parent == dev->kobj.parent) {
911 other = 1;
912 break;
913 }
914 }
915 if (!other)
916 kobject_del(dev->kobj.parent);
917
918 kobject_put(dev->kobj.parent);
919 up(&dev->class->sem);
920 }
799 } 921 }
800 device_remove_file(dev, &dev->uevent_attr); 922 device_remove_file(dev, &dev->uevent_attr);
801 device_remove_groups(dev);
802 device_remove_attrs(dev); 923 device_remove_attrs(dev);
803 bus_remove_device(dev); 924 bus_remove_device(dev);
804 925
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 6a48824e43ff..18dba8e78da7 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -94,19 +94,11 @@ int device_bind_driver(struct device *dev)
94 return ret; 94 return ret;
95} 95}
96 96
97struct stupid_thread_structure {
98 struct device_driver *drv;
99 struct device *dev;
100};
101
102static atomic_t probe_count = ATOMIC_INIT(0); 97static atomic_t probe_count = ATOMIC_INIT(0);
103static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue); 98static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue);
104 99
105static int really_probe(void *void_data) 100static int really_probe(struct device *dev, struct device_driver *drv)
106{ 101{
107 struct stupid_thread_structure *data = void_data;
108 struct device_driver *drv = data->drv;
109 struct device *dev = data->dev;
110 int ret = 0; 102 int ret = 0;
111 103
112 atomic_inc(&probe_count); 104 atomic_inc(&probe_count);
@@ -154,7 +146,6 @@ probe_failed:
154 */ 146 */
155 ret = 0; 147 ret = 0;
156done: 148done:
157 kfree(data);
158 atomic_dec(&probe_count); 149 atomic_dec(&probe_count);
159 wake_up(&probe_waitqueue); 150 wake_up(&probe_waitqueue);
160 return ret; 151 return ret;
@@ -186,16 +177,14 @@ int driver_probe_done(void)
186 * format of the ID structures, nor what is to be considered a match and 177 * format of the ID structures, nor what is to be considered a match and
187 * what is not. 178 * what is not.
188 * 179 *
189 * This function returns 1 if a match is found, an error if one occurs 180 * This function returns 1 if a match is found, -ENODEV if the device is
190 * (that is not -ENODEV or -ENXIO), and 0 otherwise. 181 * not registered, and 0 otherwise.
191 * 182 *
192 * This function must be called with @dev->sem held. When called for a 183 * This function must be called with @dev->sem held. When called for a
193 * USB interface, @dev->parent->sem must be held as well. 184 * USB interface, @dev->parent->sem must be held as well.
194 */ 185 */
195int driver_probe_device(struct device_driver * drv, struct device * dev) 186int driver_probe_device(struct device_driver * drv, struct device * dev)
196{ 187{
197 struct stupid_thread_structure *data;
198 struct task_struct *probe_task;
199 int ret = 0; 188 int ret = 0;
200 189
201 if (!device_is_registered(dev)) 190 if (!device_is_registered(dev))
@@ -206,19 +195,7 @@ int driver_probe_device(struct device_driver * drv, struct device * dev)
206 pr_debug("%s: Matched Device %s with Driver %s\n", 195 pr_debug("%s: Matched Device %s with Driver %s\n",
207 drv->bus->name, dev->bus_id, drv->name); 196 drv->bus->name, dev->bus_id, drv->name);
208 197
209 data = kmalloc(sizeof(*data), GFP_KERNEL); 198 ret = really_probe(dev, drv);
210 if (!data)
211 return -ENOMEM;
212 data->drv = drv;
213 data->dev = dev;
214
215 if (drv->multithread_probe) {
216 probe_task = kthread_run(really_probe, data,
217 "probe-%s", dev->bus_id);
218 if (IS_ERR(probe_task))
219 ret = really_probe(data);
220 } else
221 ret = really_probe(data);
222 199
223done: 200done:
224 return ret; 201 return ret;
@@ -230,30 +207,57 @@ static int __device_attach(struct device_driver * drv, void * data)
230 return driver_probe_device(drv, dev); 207 return driver_probe_device(drv, dev);
231} 208}
232 209
210static int device_probe_drivers(void *data)
211{
212 struct device *dev = data;
213 int ret = 0;
214
215 if (dev->bus) {
216 down(&dev->sem);
217 ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach);
218 up(&dev->sem);
219 }
220 return ret;
221}
222
233/** 223/**
234 * device_attach - try to attach device to a driver. 224 * device_attach - try to attach device to a driver.
235 * @dev: device. 225 * @dev: device.
236 * 226 *
237 * Walk the list of drivers that the bus has and call 227 * Walk the list of drivers that the bus has and call
238 * driver_probe_device() for each pair. If a compatible 228 * driver_probe_device() for each pair. If a compatible
239 * pair is found, break out and return. 229 * pair is found, break out and return. If the bus specifies
230 * multithreaded probing, walking the list of drivers is done
231 * on a probing thread.
240 * 232 *
241 * Returns 1 if the device was bound to a driver; 233 * Returns 1 if the device was bound to a driver;
242 * 0 if no matching device was found; error code otherwise. 234 * 0 if no matching device was found or multithreaded probing is done;
235 * -ENODEV if the device is not registered.
243 * 236 *
244 * When called for a USB interface, @dev->parent->sem must be held. 237 * When called for a USB interface, @dev->parent->sem must be held.
245 */ 238 */
246int device_attach(struct device * dev) 239int device_attach(struct device * dev)
247{ 240{
248 int ret = 0; 241 int ret = 0;
242 struct task_struct *probe_task = ERR_PTR(-ENOMEM);
249 243
250 down(&dev->sem); 244 down(&dev->sem);
251 if (dev->driver) { 245 if (dev->driver) {
252 ret = device_bind_driver(dev); 246 ret = device_bind_driver(dev);
253 if (ret == 0) 247 if (ret == 0)
254 ret = 1; 248 ret = 1;
255 } else 249 else {
256 ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); 250 dev->driver = NULL;
251 ret = 0;
252 }
253 } else {
254 if (dev->bus->multithread_probe)
255 probe_task = kthread_run(device_probe_drivers, dev,
256 "probe-%s", dev->bus_id);
257 if(IS_ERR(probe_task))
258 ret = bus_for_each_drv(dev->bus, NULL, dev,
259 __device_attach);
260 }
257 up(&dev->sem); 261 up(&dev->sem);
258 return ret; 262 return ret;
259} 263}
diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c
index cd467c9f33b3..9406259754ad 100644
--- a/drivers/base/dmapool.c
+++ b/drivers/base/dmapool.c
@@ -37,7 +37,7 @@ struct dma_page { /* cacheable header for 'allocation' bytes */
37 37
38#define POOL_TIMEOUT_JIFFIES ((100 /* msec */ * HZ) / 1000) 38#define POOL_TIMEOUT_JIFFIES ((100 /* msec */ * HZ) / 1000)
39 39
40static DECLARE_MUTEX (pools_lock); 40static DEFINE_MUTEX (pools_lock);
41 41
42static ssize_t 42static ssize_t
43show_pools (struct device *dev, struct device_attribute *attr, char *buf) 43show_pools (struct device *dev, struct device_attribute *attr, char *buf)
@@ -55,7 +55,7 @@ show_pools (struct device *dev, struct device_attribute *attr, char *buf)
55 size -= temp; 55 size -= temp;
56 next += temp; 56 next += temp;
57 57
58 down (&pools_lock); 58 mutex_lock(&pools_lock);
59 list_for_each_entry(pool, &dev->dma_pools, pools) { 59 list_for_each_entry(pool, &dev->dma_pools, pools) {
60 unsigned pages = 0; 60 unsigned pages = 0;
61 unsigned blocks = 0; 61 unsigned blocks = 0;
@@ -73,7 +73,7 @@ show_pools (struct device *dev, struct device_attribute *attr, char *buf)
73 size -= temp; 73 size -= temp;
74 next += temp; 74 next += temp;
75 } 75 }
76 up (&pools_lock); 76 mutex_unlock(&pools_lock);
77 77
78 return PAGE_SIZE - size; 78 return PAGE_SIZE - size;
79} 79}
@@ -143,7 +143,7 @@ dma_pool_create (const char *name, struct device *dev,
143 if (dev) { 143 if (dev) {
144 int ret; 144 int ret;
145 145
146 down (&pools_lock); 146 mutex_lock(&pools_lock);
147 if (list_empty (&dev->dma_pools)) 147 if (list_empty (&dev->dma_pools))
148 ret = device_create_file (dev, &dev_attr_pools); 148 ret = device_create_file (dev, &dev_attr_pools);
149 else 149 else
@@ -155,7 +155,7 @@ dma_pool_create (const char *name, struct device *dev,
155 kfree(retval); 155 kfree(retval);
156 retval = NULL; 156 retval = NULL;
157 } 157 }
158 up (&pools_lock); 158 mutex_unlock(&pools_lock);
159 } else 159 } else
160 INIT_LIST_HEAD (&retval->pools); 160 INIT_LIST_HEAD (&retval->pools);
161 161
@@ -231,11 +231,11 @@ pool_free_page (struct dma_pool *pool, struct dma_page *page)
231void 231void
232dma_pool_destroy (struct dma_pool *pool) 232dma_pool_destroy (struct dma_pool *pool)
233{ 233{
234 down (&pools_lock); 234 mutex_lock(&pools_lock);
235 list_del (&pool->pools); 235 list_del (&pool->pools);
236 if (pool->dev && list_empty (&pool->dev->dma_pools)) 236 if (pool->dev && list_empty (&pool->dev->dma_pools))
237 device_remove_file (pool->dev, &dev_attr_pools); 237 device_remove_file (pool->dev, &dev_attr_pools);
238 up (&pools_lock); 238 mutex_unlock(&pools_lock);
239 239
240 while (!list_empty (&pool->page_list)) { 240 while (!list_empty (&pool->page_list)) {
241 struct dma_page *page; 241 struct dma_page *page;
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 082bfded3854..eb11475293ed 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -149,10 +149,6 @@ void put_driver(struct device_driver * drv)
149 * We pass off most of the work to the bus_add_driver() call, 149 * We pass off most of the work to the bus_add_driver() call,
150 * since most of the things we have to do deal with the bus 150 * since most of the things we have to do deal with the bus
151 * structures. 151 * structures.
152 *
153 * The one interesting aspect is that we setup @drv->unloaded
154 * as a completion that gets complete when the driver reference
155 * count reaches 0.
156 */ 152 */
157int driver_register(struct device_driver * drv) 153int driver_register(struct device_driver * drv)
158{ 154{
@@ -162,35 +158,19 @@ int driver_register(struct device_driver * drv)
162 printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); 158 printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
163 } 159 }
164 klist_init(&drv->klist_devices, NULL, NULL); 160 klist_init(&drv->klist_devices, NULL, NULL);
165 init_completion(&drv->unloaded);
166 return bus_add_driver(drv); 161 return bus_add_driver(drv);
167} 162}
168 163
169
170/** 164/**
171 * driver_unregister - remove driver from system. 165 * driver_unregister - remove driver from system.
172 * @drv: driver. 166 * @drv: driver.
173 * 167 *
174 * Again, we pass off most of the work to the bus-level call. 168 * Again, we pass off most of the work to the bus-level call.
175 *
176 * Though, once that is done, we wait until @drv->unloaded is completed.
177 * This will block until the driver refcount reaches 0, and it is
178 * released. Only modular drivers will call this function, and we
179 * have to guarantee that it won't complete, letting the driver
180 * unload until all references are gone.
181 */ 169 */
182 170
183void driver_unregister(struct device_driver * drv) 171void driver_unregister(struct device_driver * drv)
184{ 172{
185 bus_remove_driver(drv); 173 bus_remove_driver(drv);
186 /*
187 * If the driver is a module, we are probably in
188 * the module unload path, and we want to wait
189 * for everything to unload before we can actually
190 * finish the unload.
191 */
192 if (drv->owner)
193 wait_for_completion(&drv->unloaded);
194} 174}
195 175
196/** 176/**
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index c0a979a5074b..97ab5bd1c4d6 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -31,8 +31,6 @@ enum {
31 FW_STATUS_LOADING, 31 FW_STATUS_LOADING,
32 FW_STATUS_DONE, 32 FW_STATUS_DONE,
33 FW_STATUS_ABORT, 33 FW_STATUS_ABORT,
34 FW_STATUS_READY,
35 FW_STATUS_READY_NOHOTPLUG,
36}; 34};
37 35
38static int loading_timeout = 60; /* In seconds */ 36static int loading_timeout = 60; /* In seconds */
@@ -96,9 +94,6 @@ static int firmware_uevent(struct device *dev, char **envp, int num_envp,
96 struct firmware_priv *fw_priv = dev_get_drvdata(dev); 94 struct firmware_priv *fw_priv = dev_get_drvdata(dev);
97 int i = 0, len = 0; 95 int i = 0, len = 0;
98 96
99 if (!test_bit(FW_STATUS_READY, &fw_priv->status))
100 return -ENODEV;
101
102 if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len, 97 if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &len,
103 "FIRMWARE=%s", fw_priv->fw_id)) 98 "FIRMWARE=%s", fw_priv->fw_id))
104 return -ENOMEM; 99 return -ENOMEM;
@@ -333,6 +328,7 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
333 f_dev->parent = device; 328 f_dev->parent = device;
334 f_dev->class = &firmware_class; 329 f_dev->class = &firmware_class;
335 dev_set_drvdata(f_dev, fw_priv); 330 dev_set_drvdata(f_dev, fw_priv);
331 f_dev->uevent_suppress = 1;
336 retval = device_register(f_dev); 332 retval = device_register(f_dev);
337 if (retval) { 333 if (retval) {
338 printk(KERN_ERR "%s: device_register failed\n", 334 printk(KERN_ERR "%s: device_register failed\n",
@@ -382,9 +378,7 @@ static int fw_setup_device(struct firmware *fw, struct device **dev_p,
382 } 378 }
383 379
384 if (uevent) 380 if (uevent)
385 set_bit(FW_STATUS_READY, &fw_priv->status); 381 f_dev->uevent_suppress = 0;
386 else
387 set_bit(FW_STATUS_READY_NOHOTPLUG, &fw_priv->status);
388 *dev_p = f_dev; 382 *dev_p = f_dev;
389 goto out; 383 goto out;
390 384
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index bbbb973a9d3c..05dc8764e765 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -29,6 +29,9 @@ LIST_HEAD(dpm_off_irq);
29DECLARE_MUTEX(dpm_sem); 29DECLARE_MUTEX(dpm_sem);
30DECLARE_MUTEX(dpm_list_sem); 30DECLARE_MUTEX(dpm_list_sem);
31 31
32int (*platform_enable_wakeup)(struct device *dev, int is_on);
33
34
32/** 35/**
33 * device_pm_set_parent - Specify power dependency. 36 * device_pm_set_parent - Specify power dependency.
34 * @dev: Device who needs power. 37 * @dev: Device who needs power.
diff --git a/drivers/base/power/resume.c b/drivers/base/power/resume.c
index 020be36705a6..a2c64188d713 100644
--- a/drivers/base/power/resume.c
+++ b/drivers/base/power/resume.c
@@ -26,7 +26,9 @@ int resume_device(struct device * dev)
26 26
27 TRACE_DEVICE(dev); 27 TRACE_DEVICE(dev);
28 TRACE_RESUME(0); 28 TRACE_RESUME(0);
29
29 down(&dev->sem); 30 down(&dev->sem);
31
30 if (dev->power.pm_parent 32 if (dev->power.pm_parent
31 && dev->power.pm_parent->power.power_state.event) { 33 && dev->power.pm_parent->power.power_state.event) {
32 dev_err(dev, "PM: resume from %d, parent %s still %d\n", 34 dev_err(dev, "PM: resume from %d, parent %s still %d\n",
@@ -34,15 +36,24 @@ int resume_device(struct device * dev)
34 dev->power.pm_parent->bus_id, 36 dev->power.pm_parent->bus_id,
35 dev->power.pm_parent->power.power_state.event); 37 dev->power.pm_parent->power.power_state.event);
36 } 38 }
39
37 if (dev->bus && dev->bus->resume) { 40 if (dev->bus && dev->bus->resume) {
38 dev_dbg(dev,"resuming\n"); 41 dev_dbg(dev,"resuming\n");
39 error = dev->bus->resume(dev); 42 error = dev->bus->resume(dev);
40 } 43 }
41 if (dev->class && dev->class->resume) { 44
45 if (!error && dev->type && dev->type->resume) {
46 dev_dbg(dev,"resuming\n");
47 error = dev->type->resume(dev);
48 }
49
50 if (!error && dev->class && dev->class->resume) {
42 dev_dbg(dev,"class resume\n"); 51 dev_dbg(dev,"class resume\n");
43 error = dev->class->resume(dev); 52 error = dev->class->resume(dev);
44 } 53 }
54
45 up(&dev->sem); 55 up(&dev->sem);
56
46 TRACE_RESUME(error); 57 TRACE_RESUME(error);
47 return error; 58 return error;
48} 59}
diff --git a/drivers/base/power/shutdown.c b/drivers/base/power/shutdown.c
index 3483ae4d57f5..58b6f77a1b34 100644
--- a/drivers/base/power/shutdown.c
+++ b/drivers/base/power/shutdown.c
@@ -36,7 +36,6 @@ void device_shutdown(void)
36{ 36{
37 struct device * dev, *devn; 37 struct device * dev, *devn;
38 38
39 down_write(&devices_subsys.rwsem);
40 list_for_each_entry_safe_reverse(dev, devn, &devices_subsys.kset.list, 39 list_for_each_entry_safe_reverse(dev, devn, &devices_subsys.kset.list,
41 kobj.entry) { 40 kobj.entry) {
42 if (dev->bus && dev->bus->shutdown) { 41 if (dev->bus && dev->bus->shutdown) {
@@ -47,7 +46,6 @@ void device_shutdown(void)
47 dev->driver->shutdown(dev); 46 dev->driver->shutdown(dev);
48 } 47 }
49 } 48 }
50 up_write(&devices_subsys.rwsem);
51 49
52 sysdev_shutdown(); 50 sysdev_shutdown();
53} 51}
diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c
index ece136bf97e3..42d2b86ba765 100644
--- a/drivers/base/power/suspend.c
+++ b/drivers/base/power/suspend.c
@@ -78,6 +78,18 @@ int suspend_device(struct device * dev, pm_message_t state)
78 suspend_report_result(dev->class->suspend, error); 78 suspend_report_result(dev->class->suspend, error);
79 } 79 }
80 80
81 if (!error && dev->type && dev->type->suspend && !dev->power.power_state.event) {
82 dev_dbg(dev, "%s%s\n",
83 suspend_verb(state.event),
84 ((state.event == PM_EVENT_SUSPEND)
85 && device_may_wakeup(dev))
86 ? ", may wakeup"
87 : ""
88 );
89 error = dev->type->suspend(dev, state);
90 suspend_report_result(dev->type->suspend, error);
91 }
92
81 if (!error && dev->bus && dev->bus->suspend && !dev->power.power_state.event) { 93 if (!error && dev->bus && dev->bus->suspend && !dev->power.power_state.event) {
82 dev_dbg(dev, "%s%s\n", 94 dev_dbg(dev, "%s%s\n",
83 suspend_verb(state.event), 95 suspend_verb(state.event),
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index afb71c66b6f3..a9e0b30fb1f2 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -310,14 +310,12 @@ static int proc_ide_read_driver
310 ide_driver_t *ide_drv; 310 ide_driver_t *ide_drv;
311 int len; 311 int len;
312 312
313 down_read(&dev->bus->subsys.rwsem);
314 if (dev->driver) { 313 if (dev->driver) {
315 ide_drv = container_of(dev->driver, ide_driver_t, gen_driver); 314 ide_drv = container_of(dev->driver, ide_driver_t, gen_driver);
316 len = sprintf(page, "%s version %s\n", 315 len = sprintf(page, "%s version %s\n",
317 dev->driver->name, ide_drv->version); 316 dev->driver->name, ide_drv->version);
318 } else 317 } else
319 len = sprintf(page, "ide-default version 0.9.newide\n"); 318 len = sprintf(page, "ide-default version 0.9.newide\n");
320 up_read(&dev->bus->subsys.rwsem);
321 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 319 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
322} 320}
323 321
@@ -327,7 +325,6 @@ static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
327 int ret = 1; 325 int ret = 1;
328 int err; 326 int err;
329 327
330 down_write(&dev->bus->subsys.rwsem);
331 device_release_driver(dev); 328 device_release_driver(dev);
332 /* FIXME: device can still be in use by previous driver */ 329 /* FIXME: device can still be in use by previous driver */
333 strlcpy(drive->driver_req, driver, sizeof(drive->driver_req)); 330 strlcpy(drive->driver_req, driver, sizeof(drive->driver_req));
@@ -345,7 +342,6 @@ static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
345 } 342 }
346 if (dev->driver && !strcmp(dev->driver->name, driver)) 343 if (dev->driver && !strcmp(dev->driver->name, driver))
347 ret = 0; 344 ret = 0;
348 up_write(&dev->bus->subsys.rwsem);
349 345
350 return ret; 346 return ret;
351} 347}
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index c5ace190bfe6..dbeba45a031e 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -370,9 +370,7 @@ static ssize_t fw_set_ignore_driver(struct device *dev, struct device_attribute
370 370
371 if (state == 1) { 371 if (state == 1) {
372 ud->ignore_driver = 1; 372 ud->ignore_driver = 1;
373 down_write(&ieee1394_bus_type.subsys.rwsem);
374 device_release_driver(dev); 373 device_release_driver(dev);
375 up_write(&ieee1394_bus_type.subsys.rwsem);
376 } else if (state == 0) 374 } else if (state == 0)
377 ud->ignore_driver = 0; 375 ud->ignore_driver = 0;
378 376
@@ -1163,6 +1161,7 @@ static int nodemgr_uevent(struct class_device *cdev, char **envp, int num_envp,
1163 struct unit_directory *ud; 1161 struct unit_directory *ud;
1164 int i = 0; 1162 int i = 0;
1165 int length = 0; 1163 int length = 0;
1164 int retval = 0;
1166 /* ieee1394:venNmoNspNverN */ 1165 /* ieee1394:venNmoNspNverN */
1167 char buf[8 + 1 + 3 + 8 + 2 + 8 + 2 + 8 + 3 + 8 + 1]; 1166 char buf[8 + 1 + 3 + 8 + 2 + 8 + 2 + 8 + 3 + 8 + 1];
1168 1167
@@ -1176,14 +1175,11 @@ static int nodemgr_uevent(struct class_device *cdev, char **envp, int num_envp,
1176 1175
1177#define PUT_ENVP(fmt,val) \ 1176#define PUT_ENVP(fmt,val) \
1178do { \ 1177do { \
1179 int printed; \ 1178 retval = add_uevent_var(envp, num_envp, &i, \
1180 envp[i++] = buffer; \ 1179 buffer, buffer_size, &length, \
1181 printed = snprintf(buffer, buffer_size - length, \ 1180 fmt, val); \
1182 fmt, val); \ 1181 if (retval) \
1183 if ((buffer_size - (length+printed) <= 0) || (i >= num_envp)) \ 1182 return retval; \
1184 return -ENOMEM; \
1185 length += printed+1; \
1186 buffer += printed+1; \
1187} while (0) 1183} while (0)
1188 1184
1189 PUT_ENVP("VENDOR_ID=%06x", ud->vendor_id); 1185 PUT_ENVP("VENDOR_ID=%06x", ud->vendor_id);
@@ -1393,12 +1389,10 @@ static void nodemgr_suspend_ne(struct node_entry *ne)
1393 if (ud->ne != ne) 1389 if (ud->ne != ne)
1394 continue; 1390 continue;
1395 1391
1396 down_write(&ieee1394_bus_type.subsys.rwsem);
1397 if (ud->device.driver && 1392 if (ud->device.driver &&
1398 (!ud->device.driver->suspend || 1393 (!ud->device.driver->suspend ||
1399 ud->device.driver->suspend(&ud->device, PMSG_SUSPEND))) 1394 ud->device.driver->suspend(&ud->device, PMSG_SUSPEND)))
1400 device_release_driver(&ud->device); 1395 device_release_driver(&ud->device);
1401 up_write(&ieee1394_bus_type.subsys.rwsem);
1402 } 1396 }
1403 up(&nodemgr_ud_class.sem); 1397 up(&nodemgr_ud_class.sem);
1404} 1398}
@@ -1418,10 +1412,8 @@ static void nodemgr_resume_ne(struct node_entry *ne)
1418 if (ud->ne != ne) 1412 if (ud->ne != ne)
1419 continue; 1413 continue;
1420 1414
1421 down_read(&ieee1394_bus_type.subsys.rwsem);
1422 if (ud->device.driver && ud->device.driver->resume) 1415 if (ud->device.driver && ud->device.driver->resume)
1423 ud->device.driver->resume(&ud->device); 1416 ud->device.driver->resume(&ud->device);
1424 up_read(&ieee1394_bus_type.subsys.rwsem);
1425 } 1417 }
1426 up(&nodemgr_ud_class.sem); 1418 up(&nodemgr_ud_class.sem);
1427 1419
@@ -1442,7 +1434,6 @@ static void nodemgr_update_pdrv(struct node_entry *ne)
1442 if (ud->ne != ne) 1434 if (ud->ne != ne)
1443 continue; 1435 continue;
1444 1436
1445 down_write(&ieee1394_bus_type.subsys.rwsem);
1446 if (ud->device.driver) { 1437 if (ud->device.driver) {
1447 pdrv = container_of(ud->device.driver, 1438 pdrv = container_of(ud->device.driver,
1448 struct hpsb_protocol_driver, 1439 struct hpsb_protocol_driver,
@@ -1450,7 +1441,6 @@ static void nodemgr_update_pdrv(struct node_entry *ne)
1450 if (pdrv->update && pdrv->update(ud)) 1441 if (pdrv->update && pdrv->update(ud))
1451 device_release_driver(&ud->device); 1442 device_release_driver(&ud->device);
1452 } 1443 }
1453 up_write(&ieee1394_bus_type.subsys.rwsem);
1454 } 1444 }
1455 up(&nodemgr_ud_class.sem); 1445 up(&nodemgr_ud_class.sem);
1456} 1446}
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index a00fe470a829..bd686a2a517d 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -190,16 +190,14 @@ static void gameport_run_poll_handler(unsigned long d)
190 * Basic gameport -> driver core mappings 190 * Basic gameport -> driver core mappings
191 */ 191 */
192 192
193static void gameport_bind_driver(struct gameport *gameport, struct gameport_driver *drv) 193static int gameport_bind_driver(struct gameport *gameport, struct gameport_driver *drv)
194{ 194{
195 int error; 195 int error;
196 196
197 down_write(&gameport_bus.subsys.rwsem);
198
199 gameport->dev.driver = &drv->driver; 197 gameport->dev.driver = &drv->driver;
200 if (drv->connect(gameport, drv)) { 198 if (drv->connect(gameport, drv)) {
201 gameport->dev.driver = NULL; 199 gameport->dev.driver = NULL;
202 goto out; 200 return -ENODEV;
203 } 201 }
204 202
205 error = device_bind_driver(&gameport->dev); 203 error = device_bind_driver(&gameport->dev);
@@ -211,31 +209,21 @@ static void gameport_bind_driver(struct gameport *gameport, struct gameport_driv
211 drv->description, error); 209 drv->description, error);
212 drv->disconnect(gameport); 210 drv->disconnect(gameport);
213 gameport->dev.driver = NULL; 211 gameport->dev.driver = NULL;
214 goto out; 212 return error;
215 } 213 }
216 214
217 out: 215 return 0;
218 up_write(&gameport_bus.subsys.rwsem);
219}
220
221static void gameport_release_driver(struct gameport *gameport)
222{
223 down_write(&gameport_bus.subsys.rwsem);
224 device_release_driver(&gameport->dev);
225 up_write(&gameport_bus.subsys.rwsem);
226} 216}
227 217
228static void gameport_find_driver(struct gameport *gameport) 218static void gameport_find_driver(struct gameport *gameport)
229{ 219{
230 int error; 220 int error;
231 221
232 down_write(&gameport_bus.subsys.rwsem);
233 error = device_attach(&gameport->dev); 222 error = device_attach(&gameport->dev);
234 if (error < 0) 223 if (error < 0)
235 printk(KERN_WARNING 224 printk(KERN_WARNING
236 "gameport: device_attach() failed for %s (%s), error: %d\n", 225 "gameport: device_attach() failed for %s (%s), error: %d\n",
237 gameport->phys, gameport->name, error); 226 gameport->phys, gameport->name, error);
238 up_write(&gameport_bus.subsys.rwsem);
239} 227}
240 228
241 229
@@ -483,13 +471,12 @@ static ssize_t gameport_rebind_driver(struct device *dev, struct device_attribut
483{ 471{
484 struct gameport *gameport = to_gameport_port(dev); 472 struct gameport *gameport = to_gameport_port(dev);
485 struct device_driver *drv; 473 struct device_driver *drv;
486 int retval; 474 int error;
487 475
488 retval = mutex_lock_interruptible(&gameport_mutex); 476 error = mutex_lock_interruptible(&gameport_mutex);
489 if (retval) 477 if (error)
490 return retval; 478 return error;
491 479
492 retval = count;
493 if (!strncmp(buf, "none", count)) { 480 if (!strncmp(buf, "none", count)) {
494 gameport_disconnect_port(gameport); 481 gameport_disconnect_port(gameport);
495 } else if (!strncmp(buf, "reconnect", count)) { 482 } else if (!strncmp(buf, "reconnect", count)) {
@@ -499,15 +486,15 @@ static ssize_t gameport_rebind_driver(struct device *dev, struct device_attribut
499 gameport_find_driver(gameport); 486 gameport_find_driver(gameport);
500 } else if ((drv = driver_find(buf, &gameport_bus)) != NULL) { 487 } else if ((drv = driver_find(buf, &gameport_bus)) != NULL) {
501 gameport_disconnect_port(gameport); 488 gameport_disconnect_port(gameport);
502 gameport_bind_driver(gameport, to_gameport_driver(drv)); 489 error = gameport_bind_driver(gameport, to_gameport_driver(drv));
503 put_driver(drv); 490 put_driver(drv);
504 } else { 491 } else {
505 retval = -EINVAL; 492 error = -EINVAL;
506 } 493 }
507 494
508 mutex_unlock(&gameport_mutex); 495 mutex_unlock(&gameport_mutex);
509 496
510 return retval; 497 return error ? error : count;
511} 498}
512 499
513static struct device_attribute gameport_device_attrs[] = { 500static struct device_attribute gameport_device_attrs[] = {
@@ -655,7 +642,7 @@ static void gameport_disconnect_port(struct gameport *gameport)
655 do { 642 do {
656 parent = s->parent; 643 parent = s->parent;
657 644
658 gameport_release_driver(s); 645 device_release_driver(&s->dev);
659 gameport_destroy_port(s); 646 gameport_destroy_port(s);
660 } while ((s = parent) != gameport); 647 } while ((s = parent) != gameport);
661 } 648 }
@@ -663,7 +650,7 @@ static void gameport_disconnect_port(struct gameport *gameport)
663 /* 650 /*
664 * Ok, no children left, now disconnect this port 651 * Ok, no children left, now disconnect this port
665 */ 652 */
666 gameport_release_driver(gameport); 653 device_release_driver(&gameport->dev);
667} 654}
668 655
669void gameport_rescan(struct gameport *gameport) 656void gameport_rescan(struct gameport *gameport)
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index a15e531ec755..5895202b972c 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -115,18 +115,18 @@ static int serio_match_port(const struct serio_device_id *ids, struct serio *ser
115 * Basic serio -> driver core mappings 115 * Basic serio -> driver core mappings
116 */ 116 */
117 117
118static void serio_bind_driver(struct serio *serio, struct serio_driver *drv) 118static int serio_bind_driver(struct serio *serio, struct serio_driver *drv)
119{ 119{
120 int error; 120 int error;
121 121
122 down_write(&serio_bus.subsys.rwsem);
123
124 if (serio_match_port(drv->id_table, serio)) { 122 if (serio_match_port(drv->id_table, serio)) {
123
125 serio->dev.driver = &drv->driver; 124 serio->dev.driver = &drv->driver;
126 if (serio_connect_driver(serio, drv)) { 125 if (serio_connect_driver(serio, drv)) {
127 serio->dev.driver = NULL; 126 serio->dev.driver = NULL;
128 goto out; 127 return -ENODEV;
129 } 128 }
129
130 error = device_bind_driver(&serio->dev); 130 error = device_bind_driver(&serio->dev);
131 if (error) { 131 if (error) {
132 printk(KERN_WARNING 132 printk(KERN_WARNING
@@ -136,31 +136,21 @@ static void serio_bind_driver(struct serio *serio, struct serio_driver *drv)
136 drv->description, error); 136 drv->description, error);
137 serio_disconnect_driver(serio); 137 serio_disconnect_driver(serio);
138 serio->dev.driver = NULL; 138 serio->dev.driver = NULL;
139 goto out; 139 return error;
140 } 140 }
141 } 141 }
142 out: 142 return 0;
143 up_write(&serio_bus.subsys.rwsem);
144}
145
146static void serio_release_driver(struct serio *serio)
147{
148 down_write(&serio_bus.subsys.rwsem);
149 device_release_driver(&serio->dev);
150 up_write(&serio_bus.subsys.rwsem);
151} 143}
152 144
153static void serio_find_driver(struct serio *serio) 145static void serio_find_driver(struct serio *serio)
154{ 146{
155 int error; 147 int error;
156 148
157 down_write(&serio_bus.subsys.rwsem);
158 error = device_attach(&serio->dev); 149 error = device_attach(&serio->dev);
159 if (error < 0) 150 if (error < 0)
160 printk(KERN_WARNING 151 printk(KERN_WARNING
161 "serio: device_attach() failed for %s (%s), error: %d\n", 152 "serio: device_attach() failed for %s (%s), error: %d\n",
162 serio->phys, serio->name, error); 153 serio->phys, serio->name, error);
163 up_write(&serio_bus.subsys.rwsem);
164} 154}
165 155
166 156
@@ -470,13 +460,12 @@ static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *
470{ 460{
471 struct serio *serio = to_serio_port(dev); 461 struct serio *serio = to_serio_port(dev);
472 struct device_driver *drv; 462 struct device_driver *drv;
473 int retval; 463 int error;
474 464
475 retval = mutex_lock_interruptible(&serio_mutex); 465 error = mutex_lock_interruptible(&serio_mutex);
476 if (retval) 466 if (error)
477 return retval; 467 return error;
478 468
479 retval = count;
480 if (!strncmp(buf, "none", count)) { 469 if (!strncmp(buf, "none", count)) {
481 serio_disconnect_port(serio); 470 serio_disconnect_port(serio);
482 } else if (!strncmp(buf, "reconnect", count)) { 471 } else if (!strncmp(buf, "reconnect", count)) {
@@ -486,15 +475,15 @@ static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *
486 serio_find_driver(serio); 475 serio_find_driver(serio);
487 } else if ((drv = driver_find(buf, &serio_bus)) != NULL) { 476 } else if ((drv = driver_find(buf, &serio_bus)) != NULL) {
488 serio_disconnect_port(serio); 477 serio_disconnect_port(serio);
489 serio_bind_driver(serio, to_serio_driver(drv)); 478 error = serio_bind_driver(serio, to_serio_driver(drv));
490 put_driver(drv); 479 put_driver(drv);
491 } else { 480 } else {
492 retval = -EINVAL; 481 error = -EINVAL;
493 } 482 }
494 483
495 mutex_unlock(&serio_mutex); 484 mutex_unlock(&serio_mutex);
496 485
497 return retval; 486 return error ? error : count;
498} 487}
499 488
500static ssize_t serio_show_bind_mode(struct device *dev, struct device_attribute *attr, char *buf) 489static ssize_t serio_show_bind_mode(struct device *dev, struct device_attribute *attr, char *buf)
@@ -665,7 +654,7 @@ static void serio_disconnect_port(struct serio *serio)
665 do { 654 do {
666 parent = s->parent; 655 parent = s->parent;
667 656
668 serio_release_driver(s); 657 device_release_driver(&s->dev);
669 serio_destroy_port(s); 658 serio_destroy_port(s);
670 } while ((s = parent) != serio); 659 } while ((s = parent) != serio);
671 } 660 }
@@ -673,7 +662,7 @@ static void serio_disconnect_port(struct serio *serio)
673 /* 662 /*
674 * Ok, no children left, now disconnect this port 663 * Ok, no children left, now disconnect this port
675 */ 664 */
676 serio_release_driver(serio); 665 device_release_driver(&serio->dev);
677} 666}
678 667
679void serio_rescan(struct serio *serio) 668void serio_rescan(struct serio *serio)
diff --git a/drivers/mmc/mmc_sysfs.c b/drivers/mmc/mmc_sysfs.c
index d32698b02d7f..e0e82d849d5f 100644
--- a/drivers/mmc/mmc_sysfs.c
+++ b/drivers/mmc/mmc_sysfs.c
@@ -86,31 +86,26 @@ mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
86{ 86{
87 struct mmc_card *card = dev_to_mmc_card(dev); 87 struct mmc_card *card = dev_to_mmc_card(dev);
88 char ccc[13]; 88 char ccc[13];
89 int i = 0; 89 int retval = 0, i = 0, length = 0;
90 90
91#define add_env(fmt,val) \ 91#define add_env(fmt,val) do { \
92 ({ \ 92 retval = add_uevent_var(envp, num_envp, &i, \
93 int len, ret = -ENOMEM; \ 93 buf, buf_size, &length, \
94 if (i < num_envp) { \ 94 fmt, val); \
95 envp[i++] = buf; \ 95 if (retval) \
96 len = snprintf(buf, buf_size, fmt, val) + 1; \ 96 return retval; \
97 buf_size -= len; \ 97} while (0);
98 buf += len; \
99 if (buf_size >= 0) \
100 ret = 0; \
101 } \
102 ret; \
103 })
104 98
105 for (i = 0; i < 12; i++) 99 for (i = 0; i < 12; i++)
106 ccc[i] = card->csd.cmdclass & (1 << i) ? '1' : '0'; 100 ccc[i] = card->csd.cmdclass & (1 << i) ? '1' : '0';
107 ccc[12] = '\0'; 101 ccc[12] = '\0';
108 102
109 i = 0;
110 add_env("MMC_CCC=%s", ccc); 103 add_env("MMC_CCC=%s", ccc);
111 add_env("MMC_MANFID=%06x", card->cid.manfid); 104 add_env("MMC_MANFID=%06x", card->cid.manfid);
112 add_env("MMC_NAME=%s", mmc_card_name(card)); 105 add_env("MMC_NAME=%s", mmc_card_name(card));
113 add_env("MMC_OEMID=%04x", card->cid.oemid); 106 add_env("MMC_OEMID=%04x", card->cid.oemid);
107#undef add_env
108 envp[i] = NULL;
114 109
115 return 0; 110 return 0;
116} 111}
diff --git a/drivers/net/phy/fixed.c b/drivers/net/phy/fixed.c
index 66da91bb1388..68c99b4c5255 100644
--- a/drivers/net/phy/fixed.c
+++ b/drivers/net/phy/fixed.c
@@ -276,21 +276,15 @@ static int fixed_mdio_register_device(int number, int speed, int duplex)
276 artificially, we are binding the driver here by hand; 276 artificially, we are binding the driver here by hand;
277 it will be the same for all the fixed phys anyway. 277 it will be the same for all the fixed phys anyway.
278 */ 278 */
279 down_write(&phydev->dev.bus->subsys.rwsem);
280
281 phydev->dev.driver = &fixed_mdio_driver.driver; 279 phydev->dev.driver = &fixed_mdio_driver.driver;
282 280
283 err = phydev->dev.driver->probe(&phydev->dev); 281 err = phydev->dev.driver->probe(&phydev->dev);
284 if(err < 0) { 282 if(err < 0) {
285 printk(KERN_ERR "Phy %s: problems with fixed driver\n",phydev->dev.bus_id); 283 printk(KERN_ERR "Phy %s: problems with fixed driver\n",phydev->dev.bus_id);
286 up_write(&phydev->dev.bus->subsys.rwsem);
287 goto probe_fail; 284 goto probe_fail;
288 } 285 }
289 286
290 err = device_bind_driver(&phydev->dev); 287 err = device_bind_driver(&phydev->dev);
291
292 up_write(&phydev->dev.bus->subsys.rwsem);
293
294 if (err) 288 if (err)
295 goto probe_fail; 289 goto probe_fail;
296 290
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 7d5b6d1838c8..8f01952c4850 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -208,16 +208,12 @@ struct phy_device *phy_attach(struct net_device *dev,
208 * exist, and we should use the genphy driver. */ 208 * exist, and we should use the genphy driver. */
209 if (NULL == d->driver) { 209 if (NULL == d->driver) {
210 int err; 210 int err;
211 down_write(&d->bus->subsys.rwsem);
212 d->driver = &genphy_driver.driver; 211 d->driver = &genphy_driver.driver;
213 212
214 err = d->driver->probe(d); 213 err = d->driver->probe(d);
215
216 if (err >= 0) 214 if (err >= 0)
217 err = device_bind_driver(d); 215 err = device_bind_driver(d);
218 216
219 up_write(&d->bus->subsys.rwsem);
220
221 if (err) 217 if (err)
222 return ERR_PTR(err); 218 return ERR_PTR(err);
223 } 219 }
@@ -258,11 +254,8 @@ void phy_detach(struct phy_device *phydev)
258 * was using the generic driver), we unbind the device 254 * was using the generic driver), we unbind the device
259 * from the generic driver so that there's a chance a 255 * from the generic driver so that there's a chance a
260 * real driver could be loaded */ 256 * real driver could be loaded */
261 if (phydev->dev.driver == &genphy_driver.driver) { 257 if (phydev->dev.driver == &genphy_driver.driver)
262 down_write(&phydev->dev.bus->subsys.rwsem);
263 device_release_driver(&phydev->dev); 258 device_release_driver(&phydev->dev);
264 up_write(&phydev->dev.bus->subsys.rwsem);
265 }
266} 259}
267EXPORT_SYMBOL(phy_detach); 260EXPORT_SYMBOL(phy_detach);
268 261
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index a3c1755b2f28..39e80fcef4b3 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -434,11 +434,6 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner,
434 drv->driver.mod_name = mod_name; 434 drv->driver.mod_name = mod_name;
435 drv->driver.kobj.ktype = &pci_driver_kobj_type; 435 drv->driver.kobj.ktype = &pci_driver_kobj_type;
436 436
437 if (pci_multithread_probe)
438 drv->driver.multithread_probe = pci_multithread_probe;
439 else
440 drv->driver.multithread_probe = drv->multithread_probe;
441
442 spin_lock_init(&drv->dynids.lock); 437 spin_lock_init(&drv->dynids.lock);
443 INIT_LIST_HEAD(&drv->dynids.list); 438 INIT_LIST_HEAD(&drv->dynids.list);
444 439
@@ -574,6 +569,7 @@ struct bus_type pci_bus_type = {
574 569
575static int __init pci_driver_init(void) 570static int __init pci_driver_init(void)
576{ 571{
572 pci_bus_type.multithread_probe = pci_multithread_probe;
577 return bus_register(&pci_bus_type); 573 return bus_register(&pci_bus_type);
578} 574}
579 575
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index d3eab057b2d3..2a458279327a 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -13,6 +13,7 @@
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/pci.h> 15#include <linux/pci.h>
16#include <linux/pm.h>
16#include <linux/module.h> 17#include <linux/module.h>
17#include <linux/spinlock.h> 18#include <linux/spinlock.h>
18#include <linux/string.h> 19#include <linux/string.h>
@@ -891,31 +892,48 @@ pci_disable_device(struct pci_dev *dev)
891} 892}
892 893
893/** 894/**
894 * pci_enable_wake - enable device to generate PME# when suspended 895 * pci_enable_wake - enable PCI device as wakeup event source
895 * @dev: - PCI device to operate on 896 * @dev: PCI device affected
896 * @state: - Current state of device. 897 * @state: PCI state from which device will issue wakeup events
897 * @enable: - Flag to enable or disable generation 898 * @enable: True to enable event generation; false to disable
898 *
899 * Set the bits in the device's PM Capabilities to generate PME# when
900 * the system is suspended.
901 * 899 *
902 * -EIO is returned if device doesn't have PM Capabilities. 900 * This enables the device as a wakeup event source, or disables it.
903 * -EINVAL is returned if device supports it, but can't generate wake events. 901 * When such events involves platform-specific hooks, those hooks are
904 * 0 if operation is successful. 902 * called automatically by this routine.
905 * 903 *
904 * Devices with legacy power management (no standard PCI PM capabilities)
905 * always require such platform hooks. Depending on the platform, devices
906 * supporting the standard PCI PME# signal may require such platform hooks;
907 * they always update bits in config space to allow PME# generation.
908 *
909 * -EIO is returned if the device can't ever be a wakeup event source.
910 * -EINVAL is returned if the device can't generate wakeup events from
911 * the specified PCI state. Returns zero if the operation is successful.
906 */ 912 */
907int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) 913int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
908{ 914{
909 int pm; 915 int pm;
916 int status;
910 u16 value; 917 u16 value;
911 918
919 /* Note that drivers should verify device_may_wakeup(&dev->dev)
920 * before calling this function. Platform code should report
921 * errors when drivers try to enable wakeup on devices that
922 * can't issue wakeups, or on which wakeups were disabled by
923 * userspace updating the /sys/devices.../power/wakeup file.
924 */
925
926 status = call_platform_enable_wakeup(&dev->dev, enable);
927
912 /* find PCI PM capability in list */ 928 /* find PCI PM capability in list */
913 pm = pci_find_capability(dev, PCI_CAP_ID_PM); 929 pm = pci_find_capability(dev, PCI_CAP_ID_PM);
914 930
915 /* If device doesn't support PM Capabilities, but request is to disable 931 /* If device doesn't support PM Capabilities, but caller wants to
916 * wake events, it's a nop; otherwise fail */ 932 * disable wake events, it's a NOP. Otherwise fail unless the
917 if (!pm) 933 * platform hooks handled this legacy device already.
918 return enable ? -EIO : 0; 934 */
935 if (!pm)
936 return enable ? status : 0;
919 937
920 /* Check device's ability to generate PME# */ 938 /* Check device's ability to generate PME# */
921 pci_read_config_word(dev,pm+PCI_PM_PMC,&value); 939 pci_read_config_word(dev,pm+PCI_PM_PMC,&value);
@@ -924,8 +942,14 @@ int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
924 value >>= ffs(PCI_PM_CAP_PME_MASK) - 1; /* First bit of mask */ 942 value >>= ffs(PCI_PM_CAP_PME_MASK) - 1; /* First bit of mask */
925 943
926 /* Check if it can generate PME# from requested state. */ 944 /* Check if it can generate PME# from requested state. */
927 if (!value || !(value & (1 << state))) 945 if (!value || !(value & (1 << state))) {
946 /* if it can't, revert what the platform hook changed,
947 * always reporting the base "EINVAL, can't PME#" error
948 */
949 if (enable)
950 call_platform_enable_wakeup(&dev->dev, 0);
928 return enable ? -EINVAL : 0; 951 return enable ? -EINVAL : 0;
952 }
929 953
930 pci_read_config_word(dev, pm + PCI_PM_CTRL, &value); 954 pci_read_config_word(dev, pm + PCI_PM_CTRL, &value);
931 955
@@ -936,7 +960,7 @@ int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
936 value &= ~PCI_PM_CTRL_PME_ENABLE; 960 value &= ~PCI_PM_CTRL_PME_ENABLE;
937 961
938 pci_write_config_word(dev, pm + PCI_PM_CTRL, value); 962 pci_write_config_word(dev, pm + PCI_PM_CTRL, value);
939 963
940 return 0; 964 return 0;
941} 965}
942 966
diff --git a/drivers/pnp/card.c b/drivers/pnp/card.c
index 91c047a7e635..dd6384b1efce 100644
--- a/drivers/pnp/card.c
+++ b/drivers/pnp/card.c
@@ -311,7 +311,6 @@ done:
311 return NULL; 311 return NULL;
312 312
313found: 313found:
314 down_write(&dev->dev.bus->subsys.rwsem);
315 dev->card_link = clink; 314 dev->card_link = clink;
316 dev->dev.driver = &drv->link.driver; 315 dev->dev.driver = &drv->link.driver;
317 if (pnp_bus_type.probe(&dev->dev)) 316 if (pnp_bus_type.probe(&dev->dev))
@@ -319,14 +318,11 @@ found:
319 if (device_bind_driver(&dev->dev)) 318 if (device_bind_driver(&dev->dev))
320 goto err_out; 319 goto err_out;
321 320
322 up_write(&dev->dev.bus->subsys.rwsem);
323
324 return dev; 321 return dev;
325 322
326err_out: 323err_out:
327 dev->dev.driver = NULL; 324 dev->dev.driver = NULL;
328 dev->card_link = NULL; 325 dev->card_link = NULL;
329 up_write(&dev->dev.bus->subsys.rwsem);
330 return NULL; 326 return NULL;
331} 327}
332 328
@@ -340,11 +336,9 @@ void pnp_release_card_device(struct pnp_dev * dev)
340 struct pnp_card_driver * drv = dev->card_link->driver; 336 struct pnp_card_driver * drv = dev->card_link->driver;
341 if (!drv) 337 if (!drv)
342 return; 338 return;
343 down_write(&dev->dev.bus->subsys.rwsem);
344 drv->link.remove = &card_remove; 339 drv->link.remove = &card_remove;
345 device_release_driver(&dev->dev); 340 device_release_driver(&dev->dev);
346 drv->link.remove = &card_remove_first; 341 drv->link.remove = &card_remove_first;
347 up_write(&dev->dev.bus->subsys.rwsem);
348} 342}
349 343
350/* 344/*
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 03355902c582..a23ff582db9d 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -871,6 +871,12 @@ io_subchannel_register(struct work_struct *work)
871 } 871 }
872 goto out; 872 goto out;
873 } 873 }
874 /*
875 * Now we know this subchannel will stay, we can throw
876 * our delayed uevent.
877 */
878 sch->dev.uevent_suppress = 0;
879 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
874 /* make it known to the system */ 880 /* make it known to the system */
875 ret = ccw_device_register(cdev); 881 ret = ccw_device_register(cdev);
876 if (ret) { 882 if (ret) {
diff --git a/drivers/s390/crypto/ap_bus.c b/drivers/s390/crypto/ap_bus.c
index bf37cdf43fae..5aac0ec36368 100644
--- a/drivers/s390/crypto/ap_bus.c
+++ b/drivers/s390/crypto/ap_bus.c
@@ -423,27 +423,25 @@ static int ap_uevent (struct device *dev, char **envp, int num_envp,
423 char *buffer, int buffer_size) 423 char *buffer, int buffer_size)
424{ 424{
425 struct ap_device *ap_dev = to_ap_dev(dev); 425 struct ap_device *ap_dev = to_ap_dev(dev);
426 int length; 426 int retval = 0, length = 0, i = 0;
427 427
428 if (!ap_dev) 428 if (!ap_dev)
429 return -ENODEV; 429 return -ENODEV;
430 430
431 /* Set up DEV_TYPE environment variable. */ 431 /* Set up DEV_TYPE environment variable. */
432 envp[0] = buffer; 432 retval = add_uevent_var(envp, num_envp, &i,
433 length = scnprintf(buffer, buffer_size, "DEV_TYPE=%04X", 433 buffer, buffer_size, &length,
434 ap_dev->device_type); 434 "DEV_TYPE=%04X", ap_dev->device_type);
435 if (buffer_size - length <= 0) 435 if (retval)
436 return -ENOMEM; 436 return retval;
437 buffer += length; 437
438 buffer_size -= length;
439 /* Add MODALIAS= */ 438 /* Add MODALIAS= */
440 envp[1] = buffer; 439 retval = add_uevent_var(envp, num_envp, &i,
441 length = scnprintf(buffer, buffer_size, "MODALIAS=ap:t%02X", 440 buffer, buffer_size, &length,
442 ap_dev->device_type); 441 "MODALIAS=ap:t%02X", ap_dev->device_type);
443 if (buffer_size - length <= 0) 442
444 return -ENOMEM; 443 envp[i] = NULL;
445 envp[2] = NULL; 444 return retval;
446 return 0;
447} 445}
448 446
449static struct bus_type ap_bus_type = { 447static struct bus_type ap_bus_type = {
diff --git a/drivers/s390/net/qeth_proc.c b/drivers/s390/net/qeth_proc.c
index 81f805cc5ee7..89d56c8ecdd2 100644
--- a/drivers/s390/net/qeth_proc.c
+++ b/drivers/s390/net/qeth_proc.c
@@ -37,7 +37,6 @@ qeth_procfile_seq_start(struct seq_file *s, loff_t *offset)
37 struct device *dev = NULL; 37 struct device *dev = NULL;
38 loff_t nr = 0; 38 loff_t nr = 0;
39 39
40 down_read(&qeth_ccwgroup_driver.driver.bus->subsys.rwsem);
41 if (*offset == 0) 40 if (*offset == 0)
42 return SEQ_START_TOKEN; 41 return SEQ_START_TOKEN;
43 while (1) { 42 while (1) {
@@ -53,7 +52,6 @@ qeth_procfile_seq_start(struct seq_file *s, loff_t *offset)
53static void 52static void
54qeth_procfile_seq_stop(struct seq_file *s, void* it) 53qeth_procfile_seq_stop(struct seq_file *s, void* it)
55{ 54{
56 up_read(&qeth_ccwgroup_driver.driver.bus->subsys.rwsem);
57} 55}
58 56
59static void * 57static void *
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 38c3a291efac..bd8e7f323c69 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -435,7 +435,7 @@ struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
435 struct class_device *cdev; 435 struct class_device *cdev;
436 struct Scsi_Host *shost = ERR_PTR(-ENXIO), *p; 436 struct Scsi_Host *shost = ERR_PTR(-ENXIO), *p;
437 437
438 down_read(&class->subsys.rwsem); 438 down(&class->sem);
439 list_for_each_entry(cdev, &class->children, node) { 439 list_for_each_entry(cdev, &class->children, node) {
440 p = class_to_shost(cdev); 440 p = class_to_shost(cdev);
441 if (p->host_no == hostnum) { 441 if (p->host_no == hostnum) {
@@ -443,7 +443,7 @@ struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
443 break; 443 break;
444 } 444 }
445 } 445 }
446 up_read(&class->subsys.rwsem); 446 up(&class->sem);
447 447
448 return shost; 448 return shost;
449} 449}
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index aefc7987120d..6753ca059ee4 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,
246 246
247 if (start > end) 247 if (start > end)
248 return start; 248 return start;
249 down_read(&usb_bus_type.subsys.rwsem);
250 if (iface) { 249 if (iface) {
251 driver_name = (iface->dev.driver 250 driver_name = (iface->dev.driver
252 ? iface->dev.driver->name 251 ? iface->dev.driver->name
@@ -263,7 +262,6 @@ static char *usb_dump_interface_descriptor(char *start, char *end,
263 desc->bInterfaceSubClass, 262 desc->bInterfaceSubClass,
264 desc->bInterfaceProtocol, 263 desc->bInterfaceProtocol,
265 driver_name); 264 driver_name);
266 up_read(&usb_bus_type.subsys.rwsem);
267 return start; 265 return start;
268} 266}
269 267
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 36e7a843bf91..fc3545ddb06e 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)
421 if (test_bit(ifnum, &ps->ifclaimed)) 421 if (test_bit(ifnum, &ps->ifclaimed))
422 return 0; 422 return 0;
423 423
424 /* lock against other changes to driver bindings */
425 down_write(&usb_bus_type.subsys.rwsem);
426 intf = usb_ifnum_to_if(dev, ifnum); 424 intf = usb_ifnum_to_if(dev, ifnum);
427 if (!intf) 425 if (!intf)
428 err = -ENOENT; 426 err = -ENOENT;
429 else 427 else
430 err = usb_driver_claim_interface(&usbfs_driver, intf, ps); 428 err = usb_driver_claim_interface(&usbfs_driver, intf, ps);
431 up_write(&usb_bus_type.subsys.rwsem);
432 if (err == 0) 429 if (err == 0)
433 set_bit(ifnum, &ps->ifclaimed); 430 set_bit(ifnum, &ps->ifclaimed);
434 return err; 431 return err;
@@ -444,8 +441,6 @@ static int releaseintf(struct dev_state *ps, unsigned int ifnum)
444 if (ifnum >= 8*sizeof(ps->ifclaimed)) 441 if (ifnum >= 8*sizeof(ps->ifclaimed))
445 return err; 442 return err;
446 dev = ps->dev; 443 dev = ps->dev;
447 /* lock against other changes to driver bindings */
448 down_write(&usb_bus_type.subsys.rwsem);
449 intf = usb_ifnum_to_if(dev, ifnum); 444 intf = usb_ifnum_to_if(dev, ifnum);
450 if (!intf) 445 if (!intf)
451 err = -ENOENT; 446 err = -ENOENT;
@@ -453,7 +448,6 @@ static int releaseintf(struct dev_state *ps, unsigned int ifnum)
453 usb_driver_release_interface(&usbfs_driver, intf); 448 usb_driver_release_interface(&usbfs_driver, intf);
454 err = 0; 449 err = 0;
455 } 450 }
456 up_write(&usb_bus_type.subsys.rwsem);
457 return err; 451 return err;
458} 452}
459 453
@@ -813,7 +807,6 @@ static int proc_getdriver(struct dev_state *ps, void __user *arg)
813 807
814 if (copy_from_user(&gd, arg, sizeof(gd))) 808 if (copy_from_user(&gd, arg, sizeof(gd)))
815 return -EFAULT; 809 return -EFAULT;
816 down_read(&usb_bus_type.subsys.rwsem);
817 intf = usb_ifnum_to_if(ps->dev, gd.interface); 810 intf = usb_ifnum_to_if(ps->dev, gd.interface);
818 if (!intf || !intf->dev.driver) 811 if (!intf || !intf->dev.driver)
819 ret = -ENODATA; 812 ret = -ENODATA;
@@ -822,7 +815,6 @@ static int proc_getdriver(struct dev_state *ps, void __user *arg)
822 sizeof(gd.driver)); 815 sizeof(gd.driver));
823 ret = (copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0); 816 ret = (copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0);
824 } 817 }
825 up_read(&usb_bus_type.subsys.rwsem);
826 return ret; 818 return ret;
827} 819}
828 820
@@ -1351,15 +1343,12 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1351 1343
1352 /* disconnect kernel driver from interface */ 1344 /* disconnect kernel driver from interface */
1353 case USBDEVFS_DISCONNECT: 1345 case USBDEVFS_DISCONNECT:
1354
1355 down_write(&usb_bus_type.subsys.rwsem);
1356 if (intf->dev.driver) { 1346 if (intf->dev.driver) {
1357 driver = to_usb_driver(intf->dev.driver); 1347 driver = to_usb_driver(intf->dev.driver);
1358 dev_dbg (&intf->dev, "disconnect by usbfs\n"); 1348 dev_dbg (&intf->dev, "disconnect by usbfs\n");
1359 usb_driver_release_interface(driver, intf); 1349 usb_driver_release_interface(driver, intf);
1360 } else 1350 } else
1361 retval = -ENODATA; 1351 retval = -ENODATA;
1362 up_write(&usb_bus_type.subsys.rwsem);
1363 break; 1352 break;
1364 1353
1365 /* let kernel drivers try to (re)bind to the interface */ 1354 /* 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)
1371 1360
1372 /* talk directly to the interface's driver */ 1361 /* talk directly to the interface's driver */
1373 default: 1362 default:
1374 down_read(&usb_bus_type.subsys.rwsem);
1375 if (intf->dev.driver) 1363 if (intf->dev.driver)
1376 driver = to_usb_driver(intf->dev.driver); 1364 driver = to_usb_driver(intf->dev.driver);
1377 if (driver == NULL || driver->ioctl == NULL) { 1365 if (driver == NULL || driver->ioctl == NULL) {
@@ -1381,7 +1369,6 @@ static int proc_ioctl(struct dev_state *ps, struct usbdevfs_ioctl *ctl)
1381 if (retval == -ENOIOCTLCMD) 1369 if (retval == -ENOIOCTLCMD)
1382 retval = -ENOTTY; 1370 retval = -ENOTTY;
1383 } 1371 }
1384 up_read(&usb_bus_type.subsys.rwsem);
1385 } 1372 }
1386 1373
1387 /* cleanup and return */ 1374 /* cleanup and return */
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 9e3e943f313c..e6dd2b9210f6 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)
287 * way to bind to an interface is to return the private data from 287 * way to bind to an interface is to return the private data from
288 * the driver's probe() method. 288 * the driver's probe() method.
289 * 289 *
290 * Callers must own the device lock and the driver model's usb_bus_type.subsys 290 * Callers must own the device lock, so driver probe() entries don't need
291 * writelock. So driver probe() entries don't need extra locking, 291 * extra locking, but other call contexts may need to explicitly claim that
292 * but other call contexts may need to explicitly claim those locks. 292 * lock.
293 */ 293 */
294int usb_driver_claim_interface(struct usb_driver *driver, 294int usb_driver_claim_interface(struct usb_driver *driver,
295 struct usb_interface *iface, void* priv) 295 struct usb_interface *iface, void* priv)
@@ -330,9 +330,9 @@ EXPORT_SYMBOL(usb_driver_claim_interface);
330 * also causes the driver disconnect() method to be called. 330 * also causes the driver disconnect() method to be called.
331 * 331 *
332 * This call is synchronous, and may not be used in an interrupt context. 332 * This call is synchronous, and may not be used in an interrupt context.
333 * Callers must own the device lock and the driver model's usb_bus_type.subsys 333 * Callers must own the device lock, so driver disconnect() entries don't
334 * writelock. So driver disconnect() entries don't need extra locking, 334 * need extra locking, but other call contexts may need to explicitly claim
335 * but other call contexts may need to explicitly claim those locks. 335 * that lock.
336 */ 336 */
337void usb_driver_release_interface(struct usb_driver *driver, 337void usb_driver_release_interface(struct usb_driver *driver,
338 struct usb_interface *iface) 338 struct usb_interface *iface)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index b89a98e61323..7a6028599d62 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -119,8 +119,7 @@ MODULE_PARM_DESC(use_both_schemes,
119 "first one fails"); 119 "first one fails");
120 120
121 121
122#ifdef DEBUG 122static inline char *portspeed(int portstatus)
123static inline char *portspeed (int portstatus)
124{ 123{
125 if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED)) 124 if (portstatus & (1 << USB_PORT_FEAT_HIGHSPEED))
126 return "480 Mb/s"; 125 return "480 Mb/s";
@@ -129,7 +128,6 @@ static inline char *portspeed (int portstatus)
129 else 128 else
130 return "12 Mb/s"; 129 return "12 Mb/s";
131} 130}
132#endif
133 131
134/* Note that hdev or one of its children must be locked! */ 132/* Note that hdev or one of its children must be locked! */
135static inline struct usb_hub *hdev_to_hub(struct usb_device *hdev) 133static inline struct usb_hub *hdev_to_hub(struct usb_device *hdev)
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 217a3d6d0a06..c359ccb32998 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1349,7 +1349,7 @@ static void release_interface(struct device *dev)
1349 * 1349 *
1350 * This call is synchronous. The calling context must be able to sleep, 1350 * This call is synchronous. The calling context must be able to sleep,
1351 * must own the device lock, and must not hold the driver model's USB 1351 * must own the device lock, and must not hold the driver model's USB
1352 * bus rwsem; usb device driver probe() methods cannot use this routine. 1352 * bus mutex; usb device driver probe() methods cannot use this routine.
1353 * 1353 *
1354 * Returns zero on success, or else the status code returned by the 1354 * Returns zero on success, or else the status code returned by the
1355 * underlying call that failed. On successful completion, each interface 1355 * underlying call that failed. On successful completion, each interface
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index f0d29eda3c6d..e8bbe8bc2598 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -486,9 +486,6 @@ static int ohci_run (struct ohci_hcd *ohci)
486 * or if bus glue did the same (e.g. for PCI add-in cards with 486 * or if bus glue did the same (e.g. for PCI add-in cards with
487 * PCI PM support). 487 * PCI PM support).
488 */ 488 */
489 ohci_dbg (ohci, "resetting from state '%s', control = 0x%x\n",
490 hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS),
491 ohci_readl (ohci, &ohci->regs->control));
492 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0 489 if ((ohci->hc_control & OHCI_CTRL_RWC) != 0
493 && !device_may_wakeup(hcd->self.controller)) 490 && !device_may_wakeup(hcd->self.controller))
494 device_init_wakeup(hcd->self.controller, 1); 491 device_init_wakeup(hcd->self.controller, 1);
@@ -744,9 +741,6 @@ static void ohci_stop (struct usb_hcd *hcd)
744{ 741{
745 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 742 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
746 743
747 ohci_dbg (ohci, "stop %s controller (state 0x%02x)\n",
748 hcfs2string (ohci->hc_control & OHCI_CTRL_HCFS),
749 hcd->state);
750 ohci_dump (ohci, 1); 744 ohci_dump (ohci, 1);
751 745
752 flush_scheduled_work(); 746 flush_scheduled_work();