driver-core: Add attribute argument to class_attribute show/store
authorAndi Kleen <andi@firstfloor.org>
Tue, 5 Jan 2010 11:48:07 +0000 (12:48 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 8 Mar 2010 01:04:48 +0000 (17:04 -0800)
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>
21 files changed:
drivers/base/class.c
drivers/base/cpu.c
drivers/base/firmware_class.c
drivers/base/memory.c
drivers/block/osdblk.c
drivers/block/pktcdvd.c
drivers/gpio/gpiolib.c
drivers/gpu/drm/drm_sysfs.c
drivers/infiniband/core/ucm.c
drivers/infiniband/core/user_mad.c
drivers/infiniband/core/uverbs_main.c
drivers/misc/phantom.c
drivers/mtd/ubi/build.c
drivers/net/bonding/bond_sysfs.c
drivers/staging/asus_oled/asus_oled.c
drivers/uwb/driver.c
include/linux/device.h
net/bluetooth/l2cap.c
net/bluetooth/rfcomm/core.c
net/bluetooth/rfcomm/sock.c
net/bluetooth/sco.c

index 6e2c3b064f53759d9ea0e56cf43783ff0ecd1a39..34a2de9c53859637e0be7c1318ec69f1a3ca6d3d 100644 (file)
@@ -31,7 +31,7 @@ static ssize_t class_attr_show(struct kobject *kobj, struct attribute *attr,
        ssize_t ret = -EIO;
 
        if (class_attr->show)
-               ret = class_attr->show(cp->class, buf);
+               ret = class_attr->show(cp->class, class_attr, buf);
        return ret;
 }
 
@@ -43,7 +43,7 @@ static ssize_t class_attr_store(struct kobject *kobj, struct attribute *attr,
        ssize_t ret = -EIO;
 
        if (class_attr->store)
-               ret = class_attr->store(cp->class, buf, count);
+               ret = class_attr->store(cp->class, class_attr, buf, count);
        return ret;
 }
 
index fb456b72980360ec85cc2264d8637f8e5aeafa0c..9121c77b77fae3a5d4c70f942dc67a3e65290edf 100644 (file)
@@ -79,13 +79,17 @@ void unregister_cpu(struct cpu *cpu)
 }
 
 #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
-static ssize_t cpu_probe_store(struct class *class, const char *buf,
+static ssize_t cpu_probe_store(struct class *class,
+                               struct class_attribute *attr,
+                               const char *buf,
                               size_t count)
 {
        return arch_cpu_probe(buf, count);
 }
 
-static ssize_t cpu_release_store(struct class *class, const char *buf,
+static ssize_t cpu_release_store(struct class *class,
+                               struct class_attribute *attr,
+                               const char *buf,
                                 size_t count)
 {
        return arch_cpu_release(buf, count);
index a95024166b66c0eb82a4fc6d070a4ad923544c81..6604fb33d07291f0ab87222c4bddf2096458f516 100644 (file)
@@ -69,7 +69,9 @@ fw_load_abort(struct firmware_priv *fw_priv)
 }
 
 static ssize_t
-firmware_timeout_show(struct class *class, char *buf)
+firmware_timeout_show(struct class *class,
+                     struct class_attribute *attr,
+                     char *buf)
 {
        return sprintf(buf, "%d\n", loading_timeout);
 }
@@ -87,7 +89,9 @@ firmware_timeout_show(struct class *class, char *buf)
  *     Note: zero means 'wait forever'.
  **/
 static ssize_t
-firmware_timeout_store(struct class *class, const char *buf, size_t count)
+firmware_timeout_store(struct class *class,
+                       struct class_attribute *attr,
+                       const char *buf, size_t count)
 {
        loading_timeout = simple_strtol(buf, NULL, 10);
        if (loading_timeout < 0)
index 563656ad75a1015c1ad4a57449e3bf32f0afbab4..495f15e92d4cf8fd54618671961116bc4fd6b623 100644 (file)
@@ -331,7 +331,8 @@ static int block_size_init(void)
  */
 #ifdef CONFIG_ARCH_MEMORY_PROBE
 static ssize_t
-memory_probe_store(struct class *class, const char *buf, size_t count)
+memory_probe_store(struct class *class, struct class_attribute *attr,
+                  const char *buf, size_t count)
 {
        u64 phys_addr;
        int nid;
@@ -368,7 +369,9 @@ static inline int memory_probe_init(void)
 
 /* Soft offline a page */
 static ssize_t
-store_soft_offline_page(struct class *class, const char *buf, size_t count)
+store_soft_offline_page(struct class *class,
+                       struct class_attribute *attr,
+                       const char *buf, size_t count)
 {
        int ret;
        u64 pfn;
@@ -385,7 +388,9 @@ store_soft_offline_page(struct class *class, const char *buf, size_t count)
 
 /* Forcibly offline a page, including killing processes. */
 static ssize_t
-store_hard_offline_page(struct class *class, const char *buf, size_t count)
+store_hard_offline_page(struct class *class,
+                       struct class_attribute *attr,
+                       const char *buf, size_t count)
 {
        int ret;
        u64 pfn;
index a808b1530b3bd344c290e0fed84e5d35e72d8338..eb2091aa1c19e2abf7ccfdafce320c44f7d14abb 100644 (file)
@@ -476,7 +476,9 @@ static void class_osdblk_release(struct class *cls)
        kfree(cls);
 }
 
-static ssize_t class_osdblk_list(struct class *c, char *data)
+static ssize_t class_osdblk_list(struct class *c,
+                               struct class_attribute *attr,
+                               char *data)
 {
        int n = 0;
        struct list_head *tmp;
@@ -500,7 +502,9 @@ static ssize_t class_osdblk_list(struct class *c, char *data)
        return n;
 }
 
-static ssize_t class_osdblk_add(struct class *c, const char *buf, size_t count)
+static ssize_t class_osdblk_add(struct class *c,
+                               struct class_attribute *attr,
+                               const char *buf, size_t count)
 {
        struct osdblk_device *osdev;
        ssize_t rc;
@@ -592,7 +596,9 @@ err_out_mod:
        return rc;
 }
 
-static ssize_t class_osdblk_remove(struct class *c, const char *buf,
+static ssize_t class_osdblk_remove(struct class *c,
+                                       struct class_attribute *attr,
+                                       const char *buf,
                                        size_t count)
 {
        struct osdblk_device *osdev = NULL;
index b72935b8f2036e3ea954b5560fe88fd3875f5d96..73d815d3f1b27a5fac571d1fa6e8dd7adbac5af2 100644 (file)
@@ -337,7 +337,9 @@ static void class_pktcdvd_release(struct class *cls)
 {
        kfree(cls);
 }
-static ssize_t class_pktcdvd_show_map(struct class *c, char *data)
+static ssize_t class_pktcdvd_show_map(struct class *c,
+                                       struct class_attribute *attr,
+                                       char *data)
 {
        int n = 0;
        int idx;
@@ -356,7 +358,9 @@ static ssize_t class_pktcdvd_show_map(struct class *c, char *data)
        return n;
 }
 
-static ssize_t class_pktcdvd_store_add(struct class *c, const char *buf,
+static ssize_t class_pktcdvd_store_add(struct class *c,
+                                       struct class_attribute *attr,
+                                       const char *buf,
                                        size_t count)
 {
        unsigned int major, minor;
@@ -376,7 +380,9 @@ static ssize_t class_pktcdvd_store_add(struct class *c, const char *buf,
        return -EINVAL;
 }
 
-static ssize_t class_pktcdvd_store_remove(struct class *c, const char *buf,
+static ssize_t class_pktcdvd_store_remove(struct class *c,
+                                         struct class_attribute *attr,
+                                         const char *buf,
                                        size_t count)
 {
        unsigned int major, minor;
index 9006fdb26fea2b01abc324c0f64b6ad9883eb7fa..6d1b86661e633410b5698ca075047fa2f62a12a2 100644 (file)
@@ -623,7 +623,9 @@ static const struct attribute_group gpiochip_attr_group = {
  * /sys/class/gpio/unexport ... write-only
  *     integer N ... number of GPIO to unexport
  */
-static ssize_t export_store(struct class *class, const char *buf, size_t len)
+static ssize_t export_store(struct class *class,
+                               struct class_attribute *attr,
+                               const char *buf, size_t len)
 {
        long    gpio;
        int     status;
@@ -653,7 +655,9 @@ done:
        return status ? : len;
 }
 
-static ssize_t unexport_store(struct class *class, const char *buf, size_t len)
+static ssize_t unexport_store(struct class *class,
+                               struct class_attribute *attr,
+                               const char *buf, size_t len)
 {
        long    gpio;
        int     status;
index 7e42b7e9d43a4ab67a3430360dfab11f9935a87b..b95aaf23596e1a21ebe3b6d6ea2df30c01da1b67 100644 (file)
@@ -71,7 +71,8 @@ static int drm_class_resume(struct device *dev)
 }
 
 /* Display the version of drm_core. This doesn't work right in current design */
-static ssize_t version_show(struct class *dev, char *buf)
+static ssize_t version_show(struct class *dev, struct class_attribute *attr,
+                               char *buf)
 {
        return sprintf(buf, "%s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR,
                       CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
index 1b09b735c5a8361a47904c55d505ff1674e4d560..02e209ff33fdf6733397b724a510887013653316 100644 (file)
@@ -1336,7 +1336,9 @@ static void ib_ucm_remove_one(struct ib_device *device)
        device_unregister(&ucm_dev->dev);
 }
 
-static ssize_t show_abi_version(struct class *class, char *buf)
+static ssize_t show_abi_version(struct class *class,
+                               struct class_attribute *attr,
+                               char *buf)
 {
        return sprintf(buf, "%d\n", IB_USER_CM_ABI_VERSION);
 }
index 02d360cfc2f7b930bb3ec20180e689539c94076c..d0de8f265f452c16219a7a5555751a8e2ae568a1 100644 (file)
@@ -965,7 +965,9 @@ static ssize_t show_port(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR(port, S_IRUGO, show_port, NULL);
 
-static ssize_t show_abi_version(struct class *class, char *buf)
+static ssize_t show_abi_version(struct class *class,
+                               struct class_attribute *attr,
+                               char *buf)
 {
        return sprintf(buf, "%d\n", IB_USER_MAD_ABI_VERSION);
 }
index 4fa2e65164418e033e36065baeec38d74db32032..60879399207aa2a327fcb4482ce82b94cac06730 100644 (file)
@@ -691,7 +691,9 @@ static ssize_t show_dev_abi_version(struct device *device,
 }
 static DEVICE_ATTR(abi_version, S_IRUGO, show_dev_abi_version, NULL);
 
-static ssize_t show_abi_version(struct class *class, char *buf)
+static ssize_t show_abi_version(struct class *class,
+                               struct class_attribute *attr,
+                               char *buf)
 {
        return sprintf(buf, "%d\n", IB_USER_VERBS_ABI_VERSION);
 }
index 04c27266f567548306e29df293deda919866d4e6..d30ae956030929cf4aa85ee41e8a1f2aa3c63fab 100644 (file)
@@ -497,7 +497,7 @@ static struct pci_driver phantom_pci_driver = {
        .resume = phantom_resume
 };
 
-static ssize_t phantom_show_version(struct class *cls, char *buf)
+static ssize_t phantom_show_version(struct class *cls, struct class_attribute *attr, char *buf)
 {
        return sprintf(buf, PHANTOM_VERSION "\n");
 }
index bc45ef9af17d8f94b3cd2bed56e6771837296082..fad40aa6f099c3070c64d8ba9c7321e20fcb88db 100644 (file)
@@ -89,7 +89,8 @@ DEFINE_MUTEX(ubi_devices_mutex);
 static DEFINE_SPINLOCK(ubi_devices_lock);
 
 /* "Show" method for files in '/<sysfs>/class/ubi/' */
-static ssize_t ubi_version_show(struct class *class, char *buf)
+static ssize_t ubi_version_show(struct class *class, struct class_attribute *attr,
+                               char *buf)
 {
        return sprintf(buf, "%d\n", UBI_VERSION);
 }
index 5acd557cea9ba7ab4c4cbcb36323dccee02bff20..b8bec086daa155b2c6f36884a059f4749f5636fd 100644 (file)
@@ -51,7 +51,9 @@
  * "show" function for the bond_masters attribute.
  * The class parameter is ignored.
  */
-static ssize_t bonding_show_bonds(struct class *cls, char *buf)
+static ssize_t bonding_show_bonds(struct class *cls,
+                                 struct class_attribute *attr,
+                                 char *buf)
 {
        struct net *net = current->nsproxy->net_ns;
        struct bond_net *bn = net_generic(net, bond_net_id);
@@ -98,6 +100,7 @@ static struct net_device *bond_get_by_name(struct net *net, const char *ifname)
  */
 
 static ssize_t bonding_store_bonds(struct class *cls,
+                                  struct class_attribute *attr,
                                   const char *buffer, size_t count)
 {
        struct net *net = current->nsproxy->net_ns;
index cadb6f7321add9a7b217f515f45ec8a5375711f5..7d93f50a0a64662e5c5f6ad810b52ae874f8f3b6 100644 (file)
@@ -770,7 +770,9 @@ static struct usb_driver oled_driver = {
        .id_table =     id_table,
 };
 
-static ssize_t version_show(struct class *dev, char *buf)
+static ssize_t version_show(struct class *dev,
+                           struct class_attribute *attr,
+                           char *buf)
 {
        return sprintf(buf, ASUS_OLED_UNDERSCORE_NAME " %s\n",
                       ASUS_OLED_VERSION);
index da77e41de99004c5e80d2453561e6105553a0f40..08bd6dbfd4a6d03acf870d4328633e05dd0db401 100644 (file)
 unsigned long beacon_timeout_ms = 500;
 
 static
-ssize_t beacon_timeout_ms_show(struct class *class, char *buf)
+ssize_t beacon_timeout_ms_show(struct class *class,
+                               struct class_attribute *attr,
+                               char *buf)
 {
        return scnprintf(buf, PAGE_SIZE, "%lu\n", beacon_timeout_ms);
 }
 
 static
 ssize_t beacon_timeout_ms_store(struct class *class,
+                               struct class_attribute *attr,
                                const char *buf, size_t size)
 {
        unsigned long bt;
index b30527db3ac0f69ed95089f79c1e1dd7965479fc..190f8d30d1d39cfa32f553f256f691268cd5c362 100644 (file)
@@ -251,8 +251,10 @@ extern struct device *class_find_device(struct class *class,
 
 struct class_attribute {
        struct attribute attr;
-       ssize_t (*show)(struct class *class, char *buf);
-       ssize_t (*store)(struct class *class, const char *buf, size_t count);
+       ssize_t (*show)(struct class *class, struct class_attribute *attr,
+                       char *buf);
+       ssize_t (*store)(struct class *class, struct class_attribute *attr,
+                       const char *buf, size_t count);
 };
 
 #define CLASS_ATTR(_name, _mode, _show, _store)                        \
index 400efa26ddbab7474fdfc1d1992eb204b4104f20..4db7ae2fe07dea0fcc12d142f072b8ebef5c6a58 100644 (file)
@@ -3937,7 +3937,9 @@ drop:
        return 0;
 }
 
-static ssize_t l2cap_sysfs_show(struct class *dev, char *buf)
+static ssize_t l2cap_sysfs_show(struct class *dev,
+                               struct class_attribute *attr,
+                               char *buf)
 {
        struct sock *sk;
        struct hlist_node *node;
index 89f4a59eb82b9a520886a35e6b3aa65a6286ea70..db8a68e1a5ba835c11eff1f4d1f0525642e9ab41 100644 (file)
@@ -2098,7 +2098,9 @@ static struct hci_cb rfcomm_cb = {
        .security_cfm   = rfcomm_security_cfm
 };
 
-static ssize_t rfcomm_dlc_sysfs_show(struct class *dev, char *buf)
+static ssize_t rfcomm_dlc_sysfs_show(struct class *dev,
+                                    struct class_attribute *attr,
+                                    char *buf)
 {
        struct rfcomm_session *s;
        struct list_head *pp, *p;
index 4b5968dda6736bab575a4ac2a6200dbff400d7b3..ca87d6ac6a2036dd7030c334c133e4326edcda62 100644 (file)
@@ -1061,7 +1061,9 @@ done:
        return result;
 }
 
-static ssize_t rfcomm_sock_sysfs_show(struct class *dev, char *buf)
+static ssize_t rfcomm_sock_sysfs_show(struct class *dev,
+                                     struct class_attribute *attr,
+                                     char *buf)
 {
        struct sock *sk;
        struct hlist_node *node;
index dd8f6ec57dcec21cc6401c7dba5a74af67beb782..f93b939539bc121da4448ce68e0e785b55b08416 100644 (file)
@@ -953,7 +953,9 @@ drop:
        return 0;
 }
 
-static ssize_t sco_sysfs_show(struct class *dev, char *buf)
+static ssize_t sco_sysfs_show(struct class *dev,
+                               struct class_attribute *attr,
+                               char *buf)
 {
        struct sock *sk;
        struct hlist_node *node;