]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Driver Core: add kobj_attribute handling
authorKay Sievers <kay.sievers@vrfy.org>
Fri, 2 Nov 2007 12:47:53 +0000 (13:47 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 25 Jan 2008 04:40:18 +0000 (20:40 -0800)
Add kobj_sysfs_ops to replace subsys_sysfs_ops. There is no
need for special kset operations, we want to be able to use
simple attribute operations at any kobject, not only ksets.

The whole concept of any default sysfs attribute operations
will go away with the upcoming removal of subsys_sysfs_ops.

Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
include/linux/kobject.h
lib/kobject.c

index a6dd669cda9d5d7d4b07f693a7a7f7e7e024f658..e694261de90f09a985c99f9d0c0db44b3eebde93 100644 (file)
@@ -126,6 +126,16 @@ struct kset_uevent_ops {
                      struct kobj_uevent_env *env);
 };
 
+struct kobj_attribute {
+       struct attribute attr;
+       ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,
+                       char *buf);
+       ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
+                        const char *buf, size_t count);
+};
+
+extern struct sysfs_ops kobj_sysfs_ops;
+
 /**
  * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem.
  *
index 67c3d38d48f0c3ef20b48b328133560e0bf4f662..1c343fe4ba63d1331f6154f8de338ba5233c4ed7 100644 (file)
@@ -697,6 +697,35 @@ void kset_init(struct kset * k)
        spin_lock_init(&k->list_lock);
 }
 
+/* default kobject attribute operations */
+static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr,
+                             char *buf)
+{
+       struct kobj_attribute *kattr;
+       ssize_t ret = -EIO;
+
+       kattr = container_of(attr, struct kobj_attribute, attr);
+       if (kattr->show)
+               ret = kattr->show(kobj, kattr, buf);
+       return ret;
+}
+
+static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr,
+                              const char *buf, size_t count)
+{
+       struct kobj_attribute *kattr;
+       ssize_t ret = -EIO;
+
+       kattr = container_of(attr, struct kobj_attribute, attr);
+       if (kattr->store)
+               ret = kattr->store(kobj, kattr, buf, count);
+       return ret;
+}
+
+struct sysfs_ops kobj_sysfs_ops = {
+       .show   = kobj_attr_show,
+       .store  = kobj_attr_store,
+};
 
 /**
  *     kset_add - add a kset object to the hierarchy.