diff options
Diffstat (limited to 'drivers/base/class.c')
-rw-r--r-- | drivers/base/class.c | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c index 9f737ff0fc71..59cf35894cfc 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -23,11 +23,11 @@ | |||
23 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) | 23 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) |
24 | #define to_class(obj) container_of(obj, struct class, subsys.kobj) | 24 | #define to_class(obj) container_of(obj, struct class, subsys.kobj) |
25 | 25 | ||
26 | static ssize_t | 26 | static ssize_t class_attr_show(struct kobject *kobj, struct attribute *attr, |
27 | class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) | 27 | char *buf) |
28 | { | 28 | { |
29 | struct class_attribute * class_attr = to_class_attr(attr); | 29 | struct class_attribute *class_attr = to_class_attr(attr); |
30 | struct class * dc = to_class(kobj); | 30 | struct class *dc = to_class(kobj); |
31 | ssize_t ret = -EIO; | 31 | ssize_t ret = -EIO; |
32 | 32 | ||
33 | if (class_attr->show) | 33 | if (class_attr->show) |
@@ -35,12 +35,11 @@ class_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) | |||
35 | return ret; | 35 | return ret; |
36 | } | 36 | } |
37 | 37 | ||
38 | static ssize_t | 38 | static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr, |
39 | class_attr_store(struct kobject * kobj, struct attribute * attr, | 39 | const char *buf, size_t count) |
40 | const char * buf, size_t count) | ||
41 | { | 40 | { |
42 | struct class_attribute * class_attr = to_class_attr(attr); | 41 | struct class_attribute *class_attr = to_class_attr(attr); |
43 | struct class * dc = to_class(kobj); | 42 | struct class *dc = to_class(kobj); |
44 | ssize_t ret = -EIO; | 43 | ssize_t ret = -EIO; |
45 | 44 | ||
46 | if (class_attr->store) | 45 | if (class_attr->store) |
@@ -48,7 +47,7 @@ class_attr_store(struct kobject * kobj, struct attribute * attr, | |||
48 | return ret; | 47 | return ret; |
49 | } | 48 | } |
50 | 49 | ||
51 | static void class_release(struct kobject * kobj) | 50 | static void class_release(struct kobject *kobj) |
52 | { | 51 | { |
53 | struct class *class = to_class(kobj); | 52 | struct class *class = to_class(kobj); |
54 | 53 | ||
@@ -75,17 +74,17 @@ static struct kobj_type class_ktype = { | |||
75 | static struct kset *class_kset; | 74 | static struct kset *class_kset; |
76 | 75 | ||
77 | 76 | ||
78 | int class_create_file(struct class * cls, const struct class_attribute * attr) | 77 | int class_create_file(struct class *cls, const struct class_attribute *attr) |
79 | { | 78 | { |
80 | int error; | 79 | int error; |
81 | if (cls) { | 80 | if (cls) |
82 | error = sysfs_create_file(&cls->subsys.kobj, &attr->attr); | 81 | error = sysfs_create_file(&cls->subsys.kobj, &attr->attr); |
83 | } else | 82 | else |
84 | error = -EINVAL; | 83 | error = -EINVAL; |
85 | return error; | 84 | return error; |
86 | } | 85 | } |
87 | 86 | ||
88 | void class_remove_file(struct class * cls, const struct class_attribute * attr) | 87 | void class_remove_file(struct class *cls, const struct class_attribute *attr) |
89 | { | 88 | { |
90 | if (cls) | 89 | if (cls) |
91 | sysfs_remove_file(&cls->subsys.kobj, &attr->attr); | 90 | sysfs_remove_file(&cls->subsys.kobj, &attr->attr); |
@@ -94,48 +93,48 @@ void class_remove_file(struct class * cls, const struct class_attribute * attr) | |||
94 | static struct class *class_get(struct class *cls) | 93 | static struct class *class_get(struct class *cls) |
95 | { | 94 | { |
96 | if (cls) | 95 | if (cls) |
97 | return container_of(kset_get(&cls->subsys), struct class, subsys); | 96 | return container_of(kset_get(&cls->subsys), |
97 | struct class, subsys); | ||
98 | return NULL; | 98 | return NULL; |
99 | } | 99 | } |
100 | 100 | ||
101 | static void class_put(struct class * cls) | 101 | static void class_put(struct class *cls) |
102 | { | 102 | { |
103 | if (cls) | 103 | if (cls) |
104 | kset_put(&cls->subsys); | 104 | kset_put(&cls->subsys); |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | static int add_class_attrs(struct class *cls) | |
108 | static int add_class_attrs(struct class * cls) | ||
109 | { | 108 | { |
110 | int i; | 109 | int i; |
111 | int error = 0; | 110 | int error = 0; |
112 | 111 | ||
113 | if (cls->class_attrs) { | 112 | if (cls->class_attrs) { |
114 | for (i = 0; attr_name(cls->class_attrs[i]); i++) { | 113 | for (i = 0; attr_name(cls->class_attrs[i]); i++) { |
115 | error = class_create_file(cls,&cls->class_attrs[i]); | 114 | error = class_create_file(cls, &cls->class_attrs[i]); |
116 | if (error) | 115 | if (error) |
117 | goto Err; | 116 | goto error; |
118 | } | 117 | } |
119 | } | 118 | } |
120 | Done: | 119 | done: |
121 | return error; | 120 | return error; |
122 | Err: | 121 | error: |
123 | while (--i >= 0) | 122 | while (--i >= 0) |
124 | class_remove_file(cls,&cls->class_attrs[i]); | 123 | class_remove_file(cls, &cls->class_attrs[i]); |
125 | goto Done; | 124 | goto done; |
126 | } | 125 | } |
127 | 126 | ||
128 | static void remove_class_attrs(struct class * cls) | 127 | static void remove_class_attrs(struct class *cls) |
129 | { | 128 | { |
130 | int i; | 129 | int i; |
131 | 130 | ||
132 | if (cls->class_attrs) { | 131 | if (cls->class_attrs) { |
133 | for (i = 0; attr_name(cls->class_attrs[i]); i++) | 132 | for (i = 0; attr_name(cls->class_attrs[i]); i++) |
134 | class_remove_file(cls,&cls->class_attrs[i]); | 133 | class_remove_file(cls, &cls->class_attrs[i]); |
135 | } | 134 | } |
136 | } | 135 | } |
137 | 136 | ||
138 | int class_register(struct class * cls) | 137 | int class_register(struct class *cls) |
139 | { | 138 | { |
140 | int error; | 139 | int error; |
141 | 140 | ||
@@ -167,7 +166,7 @@ int class_register(struct class * cls) | |||
167 | return error; | 166 | return error; |
168 | } | 167 | } |
169 | 168 | ||
170 | void class_unregister(struct class * cls) | 169 | void class_unregister(struct class *cls) |
171 | { | 170 | { |
172 | pr_debug("device class '%s': unregistering\n", cls->name); | 171 | pr_debug("device class '%s': unregistering\n", cls->name); |
173 | remove_class_attrs(cls); | 172 | remove_class_attrs(cls); |
@@ -249,8 +248,8 @@ void class_destroy(struct class *cls) | |||
249 | 248 | ||
250 | /* Class Device Stuff */ | 249 | /* Class Device Stuff */ |
251 | 250 | ||
252 | int class_device_create_file(struct class_device * class_dev, | 251 | int class_device_create_file(struct class_device *class_dev, |
253 | const struct class_device_attribute * attr) | 252 | const struct class_device_attribute *attr) |
254 | { | 253 | { |
255 | int error = -EINVAL; | 254 | int error = -EINVAL; |
256 | if (class_dev) | 255 | if (class_dev) |
@@ -258,8 +257,8 @@ int class_device_create_file(struct class_device * class_dev, | |||
258 | return error; | 257 | return error; |
259 | } | 258 | } |
260 | 259 | ||
261 | void class_device_remove_file(struct class_device * class_dev, | 260 | void class_device_remove_file(struct class_device *class_dev, |
262 | const struct class_device_attribute * attr) | 261 | const struct class_device_attribute *attr) |
263 | { | 262 | { |
264 | if (class_dev) | 263 | if (class_dev) |
265 | sysfs_remove_file(&class_dev->kobj, &attr->attr); | 264 | sysfs_remove_file(&class_dev->kobj, &attr->attr); |
@@ -281,12 +280,11 @@ void class_device_remove_bin_file(struct class_device *class_dev, | |||
281 | sysfs_remove_bin_file(&class_dev->kobj, attr); | 280 | sysfs_remove_bin_file(&class_dev->kobj, attr); |
282 | } | 281 | } |
283 | 282 | ||
284 | static ssize_t | 283 | static ssize_t class_device_attr_show(struct kobject *kobj, |
285 | class_device_attr_show(struct kobject * kobj, struct attribute * attr, | 284 | struct attribute *attr, char *buf) |
286 | char * buf) | ||
287 | { | 285 | { |
288 | struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr); | 286 | struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr); |
289 | struct class_device * cd = to_class_dev(kobj); | 287 | struct class_device *cd = to_class_dev(kobj); |
290 | ssize_t ret = 0; | 288 | ssize_t ret = 0; |
291 | 289 | ||
292 | if (class_dev_attr->show) | 290 | if (class_dev_attr->show) |
@@ -294,12 +292,12 @@ class_device_attr_show(struct kobject * kobj, struct attribute * attr, | |||
294 | return ret; | 292 | return ret; |
295 | } | 293 | } |
296 | 294 | ||
297 | static ssize_t | 295 | static ssize_t class_device_attr_store(struct kobject *kobj, |
298 | class_device_attr_store(struct kobject * kobj, struct attribute * attr, | 296 | struct attribute *attr, |
299 | const char * buf, size_t count) | 297 | const char *buf, size_t count) |
300 | { | 298 | { |
301 | struct class_device_attribute * class_dev_attr = to_class_dev_attr(attr); | 299 | struct class_device_attribute *class_dev_attr = to_class_dev_attr(attr); |
302 | struct class_device * cd = to_class_dev(kobj); | 300 | struct class_device *cd = to_class_dev(kobj); |
303 | ssize_t ret = 0; | 301 | ssize_t ret = 0; |
304 | 302 | ||
305 | if (class_dev_attr->store) | 303 | if (class_dev_attr->store) |
@@ -312,10 +310,10 @@ static struct sysfs_ops class_dev_sysfs_ops = { | |||
312 | .store = class_device_attr_store, | 310 | .store = class_device_attr_store, |
313 | }; | 311 | }; |
314 | 312 | ||
315 | static void class_dev_release(struct kobject * kobj) | 313 | static void class_dev_release(struct kobject *kobj) |
316 | { | 314 | { |
317 | struct class_device *cd = to_class_dev(kobj); | 315 | struct class_device *cd = to_class_dev(kobj); |
318 | struct class * cls = cd->class; | 316 | struct class *cls = cd->class; |
319 | 317 | ||
320 | pr_debug("device class '%s': release.\n", cd->class_id); | 318 | pr_debug("device class '%s': release.\n", cd->class_id); |
321 | 319 | ||
@@ -324,8 +322,8 @@ static void class_dev_release(struct kobject * kobj) | |||
324 | else if (cls->release) | 322 | else if (cls->release) |
325 | cls->release(cd); | 323 | cls->release(cd); |
326 | else { | 324 | else { |
327 | printk(KERN_ERR "Class Device '%s' does not have a release() function, " | 325 | printk(KERN_ERR "Class Device '%s' does not have a release() " |
328 | "it is broken and must be fixed.\n", | 326 | "function, it is broken and must be fixed.\n", |
329 | cd->class_id); | 327 | cd->class_id); |
330 | WARN_ON(1); | 328 | WARN_ON(1); |
331 | } | 329 | } |
@@ -436,7 +434,8 @@ static int class_uevent(struct kset *kset, struct kobject *kobj, | |||
436 | add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); | 434 | add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); |
437 | 435 | ||
438 | if (dev->driver) | 436 | if (dev->driver) |
439 | add_uevent_var(env, "PHYSDEVDRIVER=%s", dev->driver->name); | 437 | add_uevent_var(env, "PHYSDEVDRIVER=%s", |
438 | dev->driver->name); | ||
440 | } | 439 | } |
441 | 440 | ||
442 | if (class_dev->uevent) { | 441 | if (class_dev->uevent) { |
@@ -469,40 +468,40 @@ static struct kset class_obj_subsys = { | |||
469 | .uevent_ops = &class_uevent_ops, | 468 | .uevent_ops = &class_uevent_ops, |
470 | }; | 469 | }; |
471 | 470 | ||
472 | static int class_device_add_attrs(struct class_device * cd) | 471 | static int class_device_add_attrs(struct class_device *cd) |
473 | { | 472 | { |
474 | int i; | 473 | int i; |
475 | int error = 0; | 474 | int error = 0; |
476 | struct class * cls = cd->class; | 475 | struct class *cls = cd->class; |
477 | 476 | ||
478 | if (cls->class_dev_attrs) { | 477 | if (cls->class_dev_attrs) { |
479 | for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) { | 478 | for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) { |
480 | error = class_device_create_file(cd, | 479 | error = class_device_create_file(cd, |
481 | &cls->class_dev_attrs[i]); | 480 | &cls->class_dev_attrs[i]); |
482 | if (error) | 481 | if (error) |
483 | goto Err; | 482 | goto err; |
484 | } | 483 | } |
485 | } | 484 | } |
486 | Done: | 485 | done: |
487 | return error; | 486 | return error; |
488 | Err: | 487 | err: |
489 | while (--i >= 0) | 488 | while (--i >= 0) |
490 | class_device_remove_file(cd,&cls->class_dev_attrs[i]); | 489 | class_device_remove_file(cd, &cls->class_dev_attrs[i]); |
491 | goto Done; | 490 | goto done; |
492 | } | 491 | } |
493 | 492 | ||
494 | static void class_device_remove_attrs(struct class_device * cd) | 493 | static void class_device_remove_attrs(struct class_device *cd) |
495 | { | 494 | { |
496 | int i; | 495 | int i; |
497 | struct class * cls = cd->class; | 496 | struct class *cls = cd->class; |
498 | 497 | ||
499 | if (cls->class_dev_attrs) { | 498 | if (cls->class_dev_attrs) { |
500 | for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) | 499 | for (i = 0; attr_name(cls->class_dev_attrs[i]); i++) |
501 | class_device_remove_file(cd,&cls->class_dev_attrs[i]); | 500 | class_device_remove_file(cd, &cls->class_dev_attrs[i]); |
502 | } | 501 | } |
503 | } | 502 | } |
504 | 503 | ||
505 | static int class_device_add_groups(struct class_device * cd) | 504 | static int class_device_add_groups(struct class_device *cd) |
506 | { | 505 | { |
507 | int i; | 506 | int i; |
508 | int error = 0; | 507 | int error = 0; |
@@ -512,7 +511,8 @@ static int class_device_add_groups(struct class_device * cd) | |||
512 | error = sysfs_create_group(&cd->kobj, cd->groups[i]); | 511 | error = sysfs_create_group(&cd->kobj, cd->groups[i]); |
513 | if (error) { | 512 | if (error) { |
514 | while (--i >= 0) | 513 | while (--i >= 0) |
515 | sysfs_remove_group(&cd->kobj, cd->groups[i]); | 514 | sysfs_remove_group(&cd->kobj, |
515 | cd->groups[i]); | ||
516 | goto out; | 516 | goto out; |
517 | } | 517 | } |
518 | } | 518 | } |
@@ -521,14 +521,12 @@ out: | |||
521 | return error; | 521 | return error; |
522 | } | 522 | } |
523 | 523 | ||
524 | static void class_device_remove_groups(struct class_device * cd) | 524 | static void class_device_remove_groups(struct class_device *cd) |
525 | { | 525 | { |
526 | int i; | 526 | int i; |
527 | if (cd->groups) { | 527 | if (cd->groups) |
528 | for (i = 0; cd->groups[i]; i++) { | 528 | for (i = 0; cd->groups[i]; i++) |
529 | sysfs_remove_group(&cd->kobj, cd->groups[i]); | 529 | sysfs_remove_group(&cd->kobj, cd->groups[i]); |
530 | } | ||
531 | } | ||
532 | } | 530 | } |
533 | 531 | ||
534 | static ssize_t show_dev(struct class_device *class_dev, char *buf) | 532 | static ssize_t show_dev(struct class_device *class_dev, char *buf) |
@@ -653,7 +651,7 @@ int class_device_add(struct class_device *class_dev) | |||
653 | out3: | 651 | out3: |
654 | kobject_del(&class_dev->kobj); | 652 | kobject_del(&class_dev->kobj); |
655 | out2: | 653 | out2: |
656 | if(parent_class_dev) | 654 | if (parent_class_dev) |
657 | class_device_put(parent_class_dev); | 655 | class_device_put(parent_class_dev); |
658 | class_put(parent_class); | 656 | class_put(parent_class); |
659 | out1: | 657 | out1: |
@@ -670,9 +668,11 @@ int class_device_register(struct class_device *class_dev) | |||
670 | /** | 668 | /** |
671 | * class_device_create - creates a class device and registers it with sysfs | 669 | * class_device_create - creates a class device and registers it with sysfs |
672 | * @cls: pointer to the struct class that this device should be registered to. | 670 | * @cls: pointer to the struct class that this device should be registered to. |
673 | * @parent: pointer to the parent struct class_device of this new device, if any. | 671 | * @parent: pointer to the parent struct class_device of this new device, if |
672 | * any. | ||
674 | * @devt: the dev_t for the char device to be added. | 673 | * @devt: the dev_t for the char device to be added. |
675 | * @device: a pointer to a struct device that is assiociated with this class device. | 674 | * @device: a pointer to a struct device that is assiociated with this class |
675 | * device. | ||
676 | * @fmt: string for the class device's name | 676 | * @fmt: string for the class device's name |
677 | * | 677 | * |
678 | * This function can be used by char device classes. A struct | 678 | * This function can be used by char device classes. A struct |
@@ -796,7 +796,7 @@ void class_device_destroy(struct class *cls, dev_t devt) | |||
796 | class_device_unregister(class_dev); | 796 | class_device_unregister(class_dev); |
797 | } | 797 | } |
798 | 798 | ||
799 | struct class_device * class_device_get(struct class_device *class_dev) | 799 | struct class_device *class_device_get(struct class_device *class_dev) |
800 | { | 800 | { |
801 | if (class_dev) | 801 | if (class_dev) |
802 | return to_class_dev(kobject_get(&class_dev->kobj)); | 802 | return to_class_dev(kobject_get(&class_dev->kobj)); |
@@ -973,7 +973,7 @@ int class_interface_register(struct class_interface *class_intf) | |||
973 | 973 | ||
974 | void class_interface_unregister(struct class_interface *class_intf) | 974 | void class_interface_unregister(struct class_interface *class_intf) |
975 | { | 975 | { |
976 | struct class * parent = class_intf->class; | 976 | struct class *parent = class_intf->class; |
977 | struct class_device *class_dev; | 977 | struct class_device *class_dev; |
978 | struct device *dev; | 978 | struct device *dev; |
979 | 979 | ||