aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/core.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2008-01-25 01:50:12 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-25 01:50:12 -0500
commit4a3ad20ccd8f4d2a0535cf98fa83f7b561ba59a9 (patch)
tree8d0d147716466801b859a777472246ee5563f64b /drivers/base/core.c
parente374a2bfebf359f846216336de91670be40499da (diff)
Driver core: coding style fixes
Fix up a number of coding style issues in the drivers/base/ directory that have annoyed me over the years. checkpatch.pl is now very happy. Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/core.c')
-rw-r--r--drivers/base/core.c203
1 files changed, 95 insertions, 108 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index f09dde3b1e27..edf3bbeb8d6a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -24,8 +24,8 @@
24#include "base.h" 24#include "base.h"
25#include "power/power.h" 25#include "power/power.h"
26 26
27int (*platform_notify)(struct device * dev) = NULL; 27int (*platform_notify)(struct device *dev) = NULL;
28int (*platform_notify_remove)(struct device * dev) = NULL; 28int (*platform_notify_remove)(struct device *dev) = NULL;
29 29
30/* 30/*
31 * sysfs bindings for devices. 31 * sysfs bindings for devices.
@@ -51,11 +51,11 @@ EXPORT_SYMBOL(dev_driver_string);
51#define to_dev(obj) container_of(obj, struct device, kobj) 51#define to_dev(obj) container_of(obj, struct device, kobj)
52#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) 52#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
53 53
54static ssize_t 54static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
55dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) 55 char *buf)
56{ 56{
57 struct device_attribute * dev_attr = to_dev_attr(attr); 57 struct device_attribute *dev_attr = to_dev_attr(attr);
58 struct device * dev = to_dev(kobj); 58 struct device *dev = to_dev(kobj);
59 ssize_t ret = -EIO; 59 ssize_t ret = -EIO;
60 60
61 if (dev_attr->show) 61 if (dev_attr->show)
@@ -63,12 +63,11 @@ dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
63 return ret; 63 return ret;
64} 64}
65 65
66static ssize_t 66static ssize_t dev_attr_store(struct kobject *kobj, struct attribute *attr,
67dev_attr_store(struct kobject * kobj, struct attribute * attr, 67 const char *buf, size_t count)
68 const char * buf, size_t count)
69{ 68{
70 struct device_attribute * dev_attr = to_dev_attr(attr); 69 struct device_attribute *dev_attr = to_dev_attr(attr);
71 struct device * dev = to_dev(kobj); 70 struct device *dev = to_dev(kobj);
72 ssize_t ret = -EIO; 71 ssize_t ret = -EIO;
73 72
74 if (dev_attr->store) 73 if (dev_attr->store)
@@ -90,9 +89,9 @@ static struct sysfs_ops dev_sysfs_ops = {
90 * reaches 0. We forward the call to the device's release 89 * reaches 0. We forward the call to the device's release
91 * method, which should handle actually freeing the structure. 90 * method, which should handle actually freeing the structure.
92 */ 91 */
93static void device_release(struct kobject * kobj) 92static void device_release(struct kobject *kobj)
94{ 93{
95 struct device * dev = to_dev(kobj); 94 struct device *dev = to_dev(kobj);
96 95
97 if (dev->release) 96 if (dev->release)
98 dev->release(dev); 97 dev->release(dev);
@@ -101,8 +100,8 @@ static void device_release(struct kobject * kobj)
101 else if (dev->class && dev->class->dev_release) 100 else if (dev->class && dev->class->dev_release)
102 dev->class->dev_release(dev); 101 dev->class->dev_release(dev);
103 else { 102 else {
104 printk(KERN_ERR "Device '%s' does not have a release() function, " 103 printk(KERN_ERR "Device '%s' does not have a release() "
105 "it is broken and must be fixed.\n", 104 "function, it is broken and must be fixed.\n",
106 dev->bus_id); 105 dev->bus_id);
107 WARN_ON(1); 106 WARN_ON(1);
108 } 107 }
@@ -185,7 +184,8 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
185 add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name); 184 add_uevent_var(env, "PHYSDEVBUS=%s", dev->bus->name);
186 185
187 if (dev->driver) 186 if (dev->driver)
188 add_uevent_var(env, "PHYSDEVDRIVER=%s", dev->driver->name); 187 add_uevent_var(env, "PHYSDEVDRIVER=%s",
188 dev->driver->name);
189 } 189 }
190#endif 190#endif
191 191
@@ -327,7 +327,8 @@ static int device_add_groups(struct device *dev,
327 error = sysfs_create_group(&dev->kobj, groups[i]); 327 error = sysfs_create_group(&dev->kobj, groups[i]);
328 if (error) { 328 if (error) {
329 while (--i >= 0) 329 while (--i >= 0)
330 sysfs_remove_group(&dev->kobj, groups[i]); 330 sysfs_remove_group(&dev->kobj,
331 groups[i]);
331 break; 332 break;
332 } 333 }
333 } 334 }
@@ -406,14 +407,12 @@ static struct device_attribute devt_attr =
406/* kset to create /sys/devices/ */ 407/* kset to create /sys/devices/ */
407struct kset *devices_kset; 408struct kset *devices_kset;
408 409
409
410/** 410/**
411 * device_create_file - create sysfs attribute file for device. 411 * device_create_file - create sysfs attribute file for device.
412 * @dev: device. 412 * @dev: device.
413 * @attr: device attribute descriptor. 413 * @attr: device attribute descriptor.
414 */ 414 */
415 415int device_create_file(struct device *dev, struct device_attribute *attr)
416int device_create_file(struct device * dev, struct device_attribute * attr)
417{ 416{
418 int error = 0; 417 int error = 0;
419 if (get_device(dev)) { 418 if (get_device(dev)) {
@@ -424,12 +423,11 @@ int device_create_file(struct device * dev, struct device_attribute * attr)
424} 423}
425 424
426/** 425/**
427 * device_remove_file - remove sysfs attribute file. 426 * device_remove_file - remove sysfs attribute file.
428 * @dev: device. 427 * @dev: device.
429 * @attr: device attribute descriptor. 428 * @attr: device attribute descriptor.
430 */ 429 */
431 430void device_remove_file(struct device *dev, struct device_attribute *attr)
432void device_remove_file(struct device * dev, struct device_attribute * attr)
433{ 431{
434 if (get_device(dev)) { 432 if (get_device(dev)) {
435 sysfs_remove_file(&dev->kobj, &attr->attr); 433 sysfs_remove_file(&dev->kobj, &attr->attr);
@@ -510,18 +508,16 @@ static void klist_children_put(struct klist_node *n)
510 put_device(dev); 508 put_device(dev);
511} 509}
512 510
513
514/** 511/**
515 * device_initialize - init device structure. 512 * device_initialize - init device structure.
516 * @dev: device. 513 * @dev: device.
517 * 514 *
518 * This prepares the device for use by other layers, 515 * This prepares the device for use by other layers,
519 * including adding it to the device hierarchy. 516 * including adding it to the device hierarchy.
520 * It is the first half of device_register(), if called by 517 * It is the first half of device_register(), if called by
521 * that, though it can also be called separately, so one 518 * that, though it can also be called separately, so one
522 * may use @dev's fields (e.g. the refcount). 519 * may use @dev's fields (e.g. the refcount).
523 */ 520 */
524
525void device_initialize(struct device *dev) 521void device_initialize(struct device *dev)
526{ 522{
527 dev->kobj.kset = devices_kset; 523 dev->kobj.kset = devices_kset;
@@ -754,15 +750,15 @@ static void device_remove_class_symlinks(struct device *dev)
754} 750}
755 751
756/** 752/**
757 * device_add - add device to device hierarchy. 753 * device_add - add device to device hierarchy.
758 * @dev: device. 754 * @dev: device.
759 * 755 *
760 * This is part 2 of device_register(), though may be called 756 * This is part 2 of device_register(), though may be called
761 * separately _iff_ device_initialize() has been called separately. 757 * separately _iff_ device_initialize() has been called separately.
762 * 758 *
763 * This adds it to the kobject hierarchy via kobject_add(), adds it 759 * This adds it to the kobject hierarchy via kobject_add(), adds it
764 * to the global and sibling lists for the device, then 760 * to the global and sibling lists for the device, then
765 * adds it to the other relevant subsystems of the driver model. 761 * adds it to the other relevant subsystems of the driver model.
766 */ 762 */
767int device_add(struct device *dev) 763int device_add(struct device *dev)
768{ 764{
@@ -870,70 +866,63 @@ int device_add(struct device *dev)
870 goto Done; 866 goto Done;
871} 867}
872 868
873
874/** 869/**
875 * device_register - register a device with the system. 870 * device_register - register a device with the system.
876 * @dev: pointer to the device structure 871 * @dev: pointer to the device structure
877 * 872 *
878 * This happens in two clean steps - initialize the device 873 * This happens in two clean steps - initialize the device
879 * and add it to the system. The two steps can be called 874 * and add it to the system. The two steps can be called
880 * separately, but this is the easiest and most common. 875 * separately, but this is the easiest and most common.
881 * I.e. you should only call the two helpers separately if 876 * I.e. you should only call the two helpers separately if
882 * have a clearly defined need to use and refcount the device 877 * have a clearly defined need to use and refcount the device
883 * before it is added to the hierarchy. 878 * before it is added to the hierarchy.
884 */ 879 */
885
886int device_register(struct device *dev) 880int device_register(struct device *dev)
887{ 881{
888 device_initialize(dev); 882 device_initialize(dev);
889 return device_add(dev); 883 return device_add(dev);
890} 884}
891 885
892
893/** 886/**
894 * get_device - increment reference count for device. 887 * get_device - increment reference count for device.
895 * @dev: device. 888 * @dev: device.
896 * 889 *
897 * This simply forwards the call to kobject_get(), though 890 * This simply forwards the call to kobject_get(), though
898 * we do take care to provide for the case that we get a NULL 891 * we do take care to provide for the case that we get a NULL
899 * pointer passed in. 892 * pointer passed in.
900 */ 893 */
901 894struct device *get_device(struct device *dev)
902struct device * get_device(struct device * dev)
903{ 895{
904 return dev ? to_dev(kobject_get(&dev->kobj)) : NULL; 896 return dev ? to_dev(kobject_get(&dev->kobj)) : NULL;
905} 897}
906 898
907
908/** 899/**
909 * put_device - decrement reference count. 900 * put_device - decrement reference count.
910 * @dev: device in question. 901 * @dev: device in question.
911 */ 902 */
912void put_device(struct device * dev) 903void put_device(struct device *dev)
913{ 904{
914 /* might_sleep(); */ 905 /* might_sleep(); */
915 if (dev) 906 if (dev)
916 kobject_put(&dev->kobj); 907 kobject_put(&dev->kobj);
917} 908}
918 909
919
920/** 910/**
921 * device_del - delete device from system. 911 * device_del - delete device from system.
922 * @dev: device. 912 * @dev: device.
923 * 913 *
924 * This is the first part of the device unregistration 914 * This is the first part of the device unregistration
925 * sequence. This removes the device from the lists we control 915 * sequence. This removes the device from the lists we control
926 * from here, has it removed from the other driver model 916 * from here, has it removed from the other driver model
927 * subsystems it was added to in device_add(), and removes it 917 * subsystems it was added to in device_add(), and removes it
928 * from the kobject hierarchy. 918 * from the kobject hierarchy.
929 * 919 *
930 * NOTE: this should be called manually _iff_ device_add() was 920 * NOTE: this should be called manually _iff_ device_add() was
931 * also called manually. 921 * also called manually.
932 */ 922 */
933 923void device_del(struct device *dev)
934void device_del(struct device * dev)
935{ 924{
936 struct device * parent = dev->parent; 925 struct device *parent = dev->parent;
937 struct class_interface *class_intf; 926 struct class_interface *class_intf;
938 927
939 device_pm_remove(dev); 928 device_pm_remove(dev);
@@ -979,47 +968,46 @@ void device_del(struct device * dev)
979} 968}
980 969
981/** 970/**
982 * device_unregister - unregister device from system. 971 * device_unregister - unregister device from system.
983 * @dev: device going away. 972 * @dev: device going away.
984 * 973 *
985 * We do this in two parts, like we do device_register(). First, 974 * We do this in two parts, like we do device_register(). First,
986 * we remove it from all the subsystems with device_del(), then 975 * we remove it from all the subsystems with device_del(), then
987 * we decrement the reference count via put_device(). If that 976 * we decrement the reference count via put_device(). If that
988 * is the final reference count, the device will be cleaned up 977 * is the final reference count, the device will be cleaned up
989 * via device_release() above. Otherwise, the structure will 978 * via device_release() above. Otherwise, the structure will
990 * stick around until the final reference to the device is dropped. 979 * stick around until the final reference to the device is dropped.
991 */ 980 */
992void device_unregister(struct device * dev) 981void device_unregister(struct device *dev)
993{ 982{
994 pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); 983 pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__);
995 device_del(dev); 984 device_del(dev);
996 put_device(dev); 985 put_device(dev);
997} 986}
998 987
999 988static struct device *next_device(struct klist_iter *i)
1000static struct device * next_device(struct klist_iter * i)
1001{ 989{
1002 struct klist_node * n = klist_next(i); 990 struct klist_node *n = klist_next(i);
1003 return n ? container_of(n, struct device, knode_parent) : NULL; 991 return n ? container_of(n, struct device, knode_parent) : NULL;
1004} 992}
1005 993
1006/** 994/**
1007 * device_for_each_child - device child iterator. 995 * device_for_each_child - device child iterator.
1008 * @parent: parent struct device. 996 * @parent: parent struct device.
1009 * @data: data for the callback. 997 * @data: data for the callback.
1010 * @fn: function to be called for each device. 998 * @fn: function to be called for each device.
1011 * 999 *
1012 * Iterate over @parent's child devices, and call @fn for each, 1000 * Iterate over @parent's child devices, and call @fn for each,
1013 * passing it @data. 1001 * passing it @data.
1014 * 1002 *
1015 * We check the return of @fn each time. If it returns anything 1003 * We check the return of @fn each time. If it returns anything
1016 * other than 0, we break out and return that value. 1004 * other than 0, we break out and return that value.
1017 */ 1005 */
1018int device_for_each_child(struct device * parent, void * data, 1006int device_for_each_child(struct device *parent, void *data,
1019 int (*fn)(struct device *, void *)) 1007 int (*fn)(struct device *dev, void *data))
1020{ 1008{
1021 struct klist_iter i; 1009 struct klist_iter i;
1022 struct device * child; 1010 struct device *child;
1023 int error = 0; 1011 int error = 0;
1024 1012
1025 klist_iter_init(&parent->klist_children, &i); 1013 klist_iter_init(&parent->klist_children, &i);
@@ -1044,8 +1032,8 @@ int device_for_each_child(struct device * parent, void * data,
1044 * current device can be obtained, this function will return to the caller 1032 * current device can be obtained, this function will return to the caller
1045 * and not iterate over any more devices. 1033 * and not iterate over any more devices.
1046 */ 1034 */
1047struct device * device_find_child(struct device *parent, void *data, 1035struct device *device_find_child(struct device *parent, void *data,
1048 int (*match)(struct device *, void *)) 1036 int (*match)(struct device *dev, void *data))
1049{ 1037{
1050 struct klist_iter i; 1038 struct klist_iter i;
1051 struct device *child; 1039 struct device *child;
@@ -1312,8 +1300,7 @@ static int device_move_class_links(struct device *dev,
1312 class_name); 1300 class_name);
1313 if (error) 1301 if (error)
1314 sysfs_remove_link(&dev->kobj, "device"); 1302 sysfs_remove_link(&dev->kobj, "device");
1315 } 1303 } else
1316 else
1317 error = 0; 1304 error = 0;
1318out: 1305out:
1319 kfree(class_name); 1306 kfree(class_name);
@@ -1344,7 +1331,7 @@ int device_move(struct device *dev, struct device *new_parent)
1344 return -EINVAL; 1331 return -EINVAL;
1345 1332
1346 new_parent = get_device(new_parent); 1333 new_parent = get_device(new_parent);
1347 new_parent_kobj = get_device_parent (dev, new_parent); 1334 new_parent_kobj = get_device_parent(dev, new_parent);
1348 1335
1349 pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id, 1336 pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id,
1350 __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>"); 1337 __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>");
@@ -1390,7 +1377,7 @@ EXPORT_SYMBOL_GPL(device_move);
1390 */ 1377 */
1391void device_shutdown(void) 1378void device_shutdown(void)
1392{ 1379{
1393 struct device * dev, *devn; 1380 struct device *dev, *devn;
1394 1381
1395 list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list, 1382 list_for_each_entry_safe_reverse(dev, devn, &devices_kset->list,
1396 kobj.entry) { 1383 kobj.entry) {