Commit 28812fe11a21826ba4c97c6c7971a619987cd912

Authored by Andi Kleen
Committed by Greg Kroah-Hartman
1 parent 5fbcae57db

driver-core: Add attribute argument to class_attribute show/store

Passing the attribute to the low level IO functions allows all kinds
of cleanups, by sharing low level IO code without requiring
an own function for every piece of data.

Also drivers can extend the attributes with own data fields
and use that in the low level function.

This makes the class attributes the same as sysdev_class attributes
and plain attributes.

This will allow further cleanups in drivers.

Full tree sweep converting all users.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 21 changed files with 87 additions and 32 deletions Side-by-side Diff

drivers/base/class.c
... ... @@ -31,7 +31,7 @@
31 31 ssize_t ret = -EIO;
32 32  
33 33 if (class_attr->show)
34   - ret = class_attr->show(cp->class, buf);
  34 + ret = class_attr->show(cp->class, class_attr, buf);
35 35 return ret;
36 36 }
37 37  
... ... @@ -43,7 +43,7 @@
43 43 ssize_t ret = -EIO;
44 44  
45 45 if (class_attr->store)
46   - ret = class_attr->store(cp->class, buf, count);
  46 + ret = class_attr->store(cp->class, class_attr, buf, count);
47 47 return ret;
48 48 }
49 49  
... ... @@ -79,13 +79,17 @@
79 79 }
80 80  
81 81 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
82   -static ssize_t cpu_probe_store(struct class *class, const char *buf,
  82 +static ssize_t cpu_probe_store(struct class *class,
  83 + struct class_attribute *attr,
  84 + const char *buf,
83 85 size_t count)
84 86 {
85 87 return arch_cpu_probe(buf, count);
86 88 }
87 89  
88   -static ssize_t cpu_release_store(struct class *class, const char *buf,
  90 +static ssize_t cpu_release_store(struct class *class,
  91 + struct class_attribute *attr,
  92 + const char *buf,
89 93 size_t count)
90 94 {
91 95 return arch_cpu_release(buf, count);
drivers/base/firmware_class.c
... ... @@ -69,7 +69,9 @@
69 69 }
70 70  
71 71 static ssize_t
72   -firmware_timeout_show(struct class *class, char *buf)
  72 +firmware_timeout_show(struct class *class,
  73 + struct class_attribute *attr,
  74 + char *buf)
73 75 {
74 76 return sprintf(buf, "%d\n", loading_timeout);
75 77 }
... ... @@ -87,7 +89,9 @@
87 89 * Note: zero means 'wait forever'.
88 90 **/
89 91 static ssize_t
90   -firmware_timeout_store(struct class *class, const char *buf, size_t count)
  92 +firmware_timeout_store(struct class *class,
  93 + struct class_attribute *attr,
  94 + const char *buf, size_t count)
91 95 {
92 96 loading_timeout = simple_strtol(buf, NULL, 10);
93 97 if (loading_timeout < 0)
drivers/base/memory.c
... ... @@ -331,7 +331,8 @@
331 331 */
332 332 #ifdef CONFIG_ARCH_MEMORY_PROBE
333 333 static ssize_t
334   -memory_probe_store(struct class *class, const char *buf, size_t count)
  334 +memory_probe_store(struct class *class, struct class_attribute *attr,
  335 + const char *buf, size_t count)
335 336 {
336 337 u64 phys_addr;
337 338 int nid;
... ... @@ -368,7 +369,9 @@
368 369  
369 370 /* Soft offline a page */
370 371 static ssize_t
371   -store_soft_offline_page(struct class *class, const char *buf, size_t count)
  372 +store_soft_offline_page(struct class *class,
  373 + struct class_attribute *attr,
  374 + const char *buf, size_t count)
372 375 {
373 376 int ret;
374 377 u64 pfn;
... ... @@ -385,7 +388,9 @@
385 388  
386 389 /* Forcibly offline a page, including killing processes. */
387 390 static ssize_t
388   -store_hard_offline_page(struct class *class, const char *buf, size_t count)
  391 +store_hard_offline_page(struct class *class,
  392 + struct class_attribute *attr,
  393 + const char *buf, size_t count)
389 394 {
390 395 int ret;
391 396 u64 pfn;
drivers/block/osdblk.c
... ... @@ -476,7 +476,9 @@
476 476 kfree(cls);
477 477 }
478 478  
479   -static ssize_t class_osdblk_list(struct class *c, char *data)
  479 +static ssize_t class_osdblk_list(struct class *c,
  480 + struct class_attribute *attr,
  481 + char *data)
480 482 {
481 483 int n = 0;
482 484 struct list_head *tmp;
... ... @@ -500,7 +502,9 @@
500 502 return n;
501 503 }
502 504  
503   -static ssize_t class_osdblk_add(struct class *c, const char *buf, size_t count)
  505 +static ssize_t class_osdblk_add(struct class *c,
  506 + struct class_attribute *attr,
  507 + const char *buf, size_t count)
504 508 {
505 509 struct osdblk_device *osdev;
506 510 ssize_t rc;
... ... @@ -592,7 +596,9 @@
592 596 return rc;
593 597 }
594 598  
595   -static ssize_t class_osdblk_remove(struct class *c, const char *buf,
  599 +static ssize_t class_osdblk_remove(struct class *c,
  600 + struct class_attribute *attr,
  601 + const char *buf,
596 602 size_t count)
597 603 {
598 604 struct osdblk_device *osdev = NULL;
drivers/block/pktcdvd.c
... ... @@ -337,7 +337,9 @@
337 337 {
338 338 kfree(cls);
339 339 }
340   -static ssize_t class_pktcdvd_show_map(struct class *c, char *data)
  340 +static ssize_t class_pktcdvd_show_map(struct class *c,
  341 + struct class_attribute *attr,
  342 + char *data)
341 343 {
342 344 int n = 0;
343 345 int idx;
... ... @@ -356,7 +358,9 @@
356 358 return n;
357 359 }
358 360  
359   -static ssize_t class_pktcdvd_store_add(struct class *c, const char *buf,
  361 +static ssize_t class_pktcdvd_store_add(struct class *c,
  362 + struct class_attribute *attr,
  363 + const char *buf,
360 364 size_t count)
361 365 {
362 366 unsigned int major, minor;
... ... @@ -376,7 +380,9 @@
376 380 return -EINVAL;
377 381 }
378 382  
379   -static ssize_t class_pktcdvd_store_remove(struct class *c, const char *buf,
  383 +static ssize_t class_pktcdvd_store_remove(struct class *c,
  384 + struct class_attribute *attr,
  385 + const char *buf,
380 386 size_t count)
381 387 {
382 388 unsigned int major, minor;
drivers/gpio/gpiolib.c
... ... @@ -623,7 +623,9 @@
623 623 * /sys/class/gpio/unexport ... write-only
624 624 * integer N ... number of GPIO to unexport
625 625 */
626   -static ssize_t export_store(struct class *class, const char *buf, size_t len)
  626 +static ssize_t export_store(struct class *class,
  627 + struct class_attribute *attr,
  628 + const char *buf, size_t len)
627 629 {
628 630 long gpio;
629 631 int status;
... ... @@ -653,7 +655,9 @@
653 655 return status ? : len;
654 656 }
655 657  
656   -static ssize_t unexport_store(struct class *class, const char *buf, size_t len)
  658 +static ssize_t unexport_store(struct class *class,
  659 + struct class_attribute *attr,
  660 + const char *buf, size_t len)
657 661 {
658 662 long gpio;
659 663 int status;
drivers/gpu/drm/drm_sysfs.c
... ... @@ -71,7 +71,8 @@
71 71 }
72 72  
73 73 /* Display the version of drm_core. This doesn't work right in current design */
74   -static ssize_t version_show(struct class *dev, char *buf)
  74 +static ssize_t version_show(struct class *dev, struct class_attribute *attr,
  75 + char *buf)
75 76 {
76 77 return sprintf(buf, "%s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR,
77 78 CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
drivers/infiniband/core/ucm.c
... ... @@ -1336,7 +1336,9 @@
1336 1336 device_unregister(&ucm_dev->dev);
1337 1337 }
1338 1338  
1339   -static ssize_t show_abi_version(struct class *class, char *buf)
  1339 +static ssize_t show_abi_version(struct class *class,
  1340 + struct class_attribute *attr,
  1341 + char *buf)
1340 1342 {
1341 1343 return sprintf(buf, "%d\n", IB_USER_CM_ABI_VERSION);
1342 1344 }
drivers/infiniband/core/user_mad.c
... ... @@ -965,7 +965,9 @@
965 965 }
966 966 static DEVICE_ATTR(port, S_IRUGO, show_port, NULL);
967 967  
968   -static ssize_t show_abi_version(struct class *class, char *buf)
  968 +static ssize_t show_abi_version(struct class *class,
  969 + struct class_attribute *attr,
  970 + char *buf)
969 971 {
970 972 return sprintf(buf, "%d\n", IB_USER_MAD_ABI_VERSION);
971 973 }
drivers/infiniband/core/uverbs_main.c
... ... @@ -691,7 +691,9 @@
691 691 }
692 692 static DEVICE_ATTR(abi_version, S_IRUGO, show_dev_abi_version, NULL);
693 693  
694   -static ssize_t show_abi_version(struct class *class, char *buf)
  694 +static ssize_t show_abi_version(struct class *class,
  695 + struct class_attribute *attr,
  696 + char *buf)
695 697 {
696 698 return sprintf(buf, "%d\n", IB_USER_VERBS_ABI_VERSION);
697 699 }
drivers/misc/phantom.c
... ... @@ -497,7 +497,7 @@
497 497 .resume = phantom_resume
498 498 };
499 499  
500   -static ssize_t phantom_show_version(struct class *cls, char *buf)
  500 +static ssize_t phantom_show_version(struct class *cls, struct class_attribute *attr, char *buf)
501 501 {
502 502 return sprintf(buf, PHANTOM_VERSION "\n");
503 503 }
drivers/mtd/ubi/build.c
... ... @@ -89,7 +89,8 @@
89 89 static DEFINE_SPINLOCK(ubi_devices_lock);
90 90  
91 91 /* "Show" method for files in '/<sysfs>/class/ubi/' */
92   -static ssize_t ubi_version_show(struct class *class, char *buf)
  92 +static ssize_t ubi_version_show(struct class *class, struct class_attribute *attr,
  93 + char *buf)
93 94 {
94 95 return sprintf(buf, "%d\n", UBI_VERSION);
95 96 }
drivers/net/bonding/bond_sysfs.c
... ... @@ -51,7 +51,9 @@
51 51 * "show" function for the bond_masters attribute.
52 52 * The class parameter is ignored.
53 53 */
54   -static ssize_t bonding_show_bonds(struct class *cls, char *buf)
  54 +static ssize_t bonding_show_bonds(struct class *cls,
  55 + struct class_attribute *attr,
  56 + char *buf)
55 57 {
56 58 struct net *net = current->nsproxy->net_ns;
57 59 struct bond_net *bn = net_generic(net, bond_net_id);
... ... @@ -98,6 +100,7 @@
98 100 */
99 101  
100 102 static ssize_t bonding_store_bonds(struct class *cls,
  103 + struct class_attribute *attr,
101 104 const char *buffer, size_t count)
102 105 {
103 106 struct net *net = current->nsproxy->net_ns;
drivers/staging/asus_oled/asus_oled.c
... ... @@ -770,7 +770,9 @@
770 770 .id_table = id_table,
771 771 };
772 772  
773   -static ssize_t version_show(struct class *dev, char *buf)
  773 +static ssize_t version_show(struct class *dev,
  774 + struct class_attribute *attr,
  775 + char *buf)
774 776 {
775 777 return sprintf(buf, ASUS_OLED_UNDERSCORE_NAME " %s\n",
776 778 ASUS_OLED_VERSION);
drivers/uwb/driver.c
... ... @@ -74,13 +74,16 @@
74 74 unsigned long beacon_timeout_ms = 500;
75 75  
76 76 static
77   -ssize_t beacon_timeout_ms_show(struct class *class, char *buf)
  77 +ssize_t beacon_timeout_ms_show(struct class *class,
  78 + struct class_attribute *attr,
  79 + char *buf)
78 80 {
79 81 return scnprintf(buf, PAGE_SIZE, "%lu\n", beacon_timeout_ms);
80 82 }
81 83  
82 84 static
83 85 ssize_t beacon_timeout_ms_store(struct class *class,
  86 + struct class_attribute *attr,
84 87 const char *buf, size_t size)
85 88 {
86 89 unsigned long bt;
include/linux/device.h
... ... @@ -251,8 +251,10 @@
251 251  
252 252 struct class_attribute {
253 253 struct attribute attr;
254   - ssize_t (*show)(struct class *class, char *buf);
255   - ssize_t (*store)(struct class *class, const char *buf, size_t count);
  254 + ssize_t (*show)(struct class *class, struct class_attribute *attr,
  255 + char *buf);
  256 + ssize_t (*store)(struct class *class, struct class_attribute *attr,
  257 + const char *buf, size_t count);
256 258 };
257 259  
258 260 #define CLASS_ATTR(_name, _mode, _show, _store) \
net/bluetooth/l2cap.c
... ... @@ -3937,7 +3937,9 @@
3937 3937 return 0;
3938 3938 }
3939 3939  
3940   -static ssize_t l2cap_sysfs_show(struct class *dev, char *buf)
  3940 +static ssize_t l2cap_sysfs_show(struct class *dev,
  3941 + struct class_attribute *attr,
  3942 + char *buf)
3941 3943 {
3942 3944 struct sock *sk;
3943 3945 struct hlist_node *node;
net/bluetooth/rfcomm/core.c
... ... @@ -2098,7 +2098,9 @@
2098 2098 .security_cfm = rfcomm_security_cfm
2099 2099 };
2100 2100  
2101   -static ssize_t rfcomm_dlc_sysfs_show(struct class *dev, char *buf)
  2101 +static ssize_t rfcomm_dlc_sysfs_show(struct class *dev,
  2102 + struct class_attribute *attr,
  2103 + char *buf)
2102 2104 {
2103 2105 struct rfcomm_session *s;
2104 2106 struct list_head *pp, *p;
net/bluetooth/rfcomm/sock.c
... ... @@ -1061,7 +1061,9 @@
1061 1061 return result;
1062 1062 }
1063 1063  
1064   -static ssize_t rfcomm_sock_sysfs_show(struct class *dev, char *buf)
  1064 +static ssize_t rfcomm_sock_sysfs_show(struct class *dev,
  1065 + struct class_attribute *attr,
  1066 + char *buf)
1065 1067 {
1066 1068 struct sock *sk;
1067 1069 struct hlist_node *node;
... ... @@ -953,7 +953,9 @@
953 953 return 0;
954 954 }
955 955  
956   -static ssize_t sco_sysfs_show(struct class *dev, char *buf)
  956 +static ssize_t sco_sysfs_show(struct class *dev,
  957 + struct class_attribute *attr,
  958 + char *buf)
957 959 {
958 960 struct sock *sk;
959 961 struct hlist_node *node;