diff options
-rw-r--r-- | drivers/base/class.c | 17 | ||||
-rw-r--r-- | drivers/base/core.c | 7 | ||||
-rw-r--r-- | include/linux/device.h | 5 |
3 files changed, 28 insertions, 1 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c index e078bc21d52e..cbdf47c0c60d 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -19,6 +19,8 @@ | |||
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include "base.h" | 20 | #include "base.h" |
21 | 21 | ||
22 | extern struct subsystem devices_subsys; | ||
23 | |||
22 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) | 24 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) |
23 | #define to_class(obj) container_of(obj, struct class, subsys.kset.kobj) | 25 | #define to_class(obj) container_of(obj, struct class, subsys.kset.kobj) |
24 | 26 | ||
@@ -878,7 +880,22 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
878 | class_put(parent); | 880 | class_put(parent); |
879 | } | 881 | } |
880 | 882 | ||
883 | int virtual_device_parent(struct device *dev) | ||
884 | { | ||
885 | if (!dev->class) | ||
886 | return -ENODEV; | ||
887 | |||
888 | if (!dev->class->virtual_dir) { | ||
889 | static struct kobject *virtual_dir = NULL; | ||
881 | 890 | ||
891 | if (!virtual_dir) | ||
892 | virtual_dir = kobject_add_dir(&devices_subsys.kset.kobj, "virtual"); | ||
893 | dev->class->virtual_dir = kobject_add_dir(virtual_dir, dev->class->name); | ||
894 | } | ||
895 | |||
896 | dev->kobj.parent = dev->class->virtual_dir; | ||
897 | return 0; | ||
898 | } | ||
882 | 899 | ||
883 | int __init classes_init(void) | 900 | int __init classes_init(void) |
884 | { | 901 | { |
diff --git a/drivers/base/core.c b/drivers/base/core.c index 0db47561331e..e21a65fc043e 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -378,6 +378,13 @@ int device_add(struct device *dev) | |||
378 | if (!dev || !strlen(dev->bus_id)) | 378 | if (!dev || !strlen(dev->bus_id)) |
379 | goto Error; | 379 | goto Error; |
380 | 380 | ||
381 | /* if this is a class device, and has no parent, create one */ | ||
382 | if ((dev->class) && (dev->parent == NULL)) { | ||
383 | error = virtual_device_parent(dev); | ||
384 | if (error) | ||
385 | goto Error; | ||
386 | } | ||
387 | |||
381 | parent = get_device(dev->parent); | 388 | parent = get_device(dev->parent); |
382 | 389 | ||
383 | pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); | 390 | pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); |
diff --git a/include/linux/device.h b/include/linux/device.h index 3400e09bf458..bbb0d6b5d232 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -149,6 +149,8 @@ struct class { | |||
149 | struct list_head interfaces; | 149 | struct list_head interfaces; |
150 | struct semaphore sem; /* locks both the children and interfaces lists */ | 150 | struct semaphore sem; /* locks both the children and interfaces lists */ |
151 | 151 | ||
152 | struct kobject *virtual_dir; | ||
153 | |||
152 | struct class_attribute * class_attrs; | 154 | struct class_attribute * class_attrs; |
153 | struct class_device_attribute * class_dev_attrs; | 155 | struct class_device_attribute * class_dev_attrs; |
154 | struct device_attribute * dev_attrs; | 156 | struct device_attribute * dev_attrs; |
@@ -291,7 +293,6 @@ extern struct class_device *class_device_create(struct class *cls, | |||
291 | __attribute__((format(printf,5,6))); | 293 | __attribute__((format(printf,5,6))); |
292 | extern void class_device_destroy(struct class *cls, dev_t devt); | 294 | extern void class_device_destroy(struct class *cls, dev_t devt); |
293 | 295 | ||
294 | |||
295 | /* interface for exporting device attributes */ | 296 | /* interface for exporting device attributes */ |
296 | struct device_attribute { | 297 | struct device_attribute { |
297 | struct attribute attr; | 298 | struct attribute attr; |
@@ -400,6 +401,8 @@ extern struct device *device_create(struct class *cls, struct device *parent, | |||
400 | __attribute__((format(printf,4,5))); | 401 | __attribute__((format(printf,4,5))); |
401 | extern void device_destroy(struct class *cls, dev_t devt); | 402 | extern void device_destroy(struct class *cls, dev_t devt); |
402 | 403 | ||
404 | extern int virtual_device_parent(struct device *dev); | ||
405 | |||
403 | /* | 406 | /* |
404 | * Platform "fixup" functions - allow the platform to have their say | 407 | * Platform "fixup" functions - allow the platform to have their say |
405 | * about devices and actions that the general device layer doesn't | 408 | * about devices and actions that the general device layer doesn't |