Re: [PATCH 34/54] Driver Core: add kobj_attribute handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri,  2 Nov 2007 16:59:12 -0700,
Greg Kroah-Hartman <[email protected]> wrote:

> From: Kay Sievers <[email protected]>
> 
> 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 <[email protected]>
> Signed-off-by: Greg Kroah-Hartman <[email protected]>
> ---
>  include/linux/kobject.h |   10 ++++++++++
>  lib/kobject.c           |   29 +++++++++++++++++++++++++++++
>  2 files changed, 39 insertions(+), 0 deletions(-)

How about adding some simple wrappers around the new kobj_attribute
structure? This makes the layering clearer.

Signed-off-by: Cornelia Huck <[email protected]>
---
 include/linux/kobject.h |    7 ++++++-
 lib/kobject.c           |   22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

Index: linux-2.6/include/linux/kobject.h
===================================================================
--- linux-2.6.orig/include/linux/kobject.h	2007-11-05 11:12:49.000000000 +0100
+++ linux-2.6/include/linux/kobject.h	2007-11-05 13:24:55.000000000 +0100
@@ -126,7 +126,12 @@ struct kobj_attribute {
 	ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
 			 const char *buf, size_t count);
 };
-
+#define KOBJ_ATTR(_name,_mode,_show,_store)		\
+	struct kobj_attribute kobj_attr_##_name =	\
+		__ATTR(_name,_mode,_show,_store)
+extern int __must_check kobject_create_file(struct kobject *,
+					    struct kobj_attribute *);
+extern void kobject_remove_file(struct kobject *,struct kobj_attribute *);
 extern struct sysfs_ops kobj_sysfs_ops;
 
 /**
Index: linux-2.6/lib/kobject.c
===================================================================
--- linux-2.6.orig/lib/kobject.c	2007-11-05 11:12:49.000000000 +0100
+++ linux-2.6/lib/kobject.c	2007-11-05 13:36:45.000000000 +0100
@@ -577,6 +577,28 @@ struct sysfs_ops kobj_sysfs_ops = {
 	.store	= kobj_attr_store,
 };
 
+/**
+ * kobject_create_file() - create an attribute file for a kobject
+ * @kobj: kobject the attribute is created for
+ * @attr: attribute to be created
+ */
+int kobject_create_file(struct kobject *kobj, struct kobj_attribute *attr)
+{
+	return sysfs_create_file(kobj, &attr->attr);
+}
+EXPORT_SYMBOL_GPL(kobject_create_file);
+
+/**
+ * kobject_remove_file() - remove an attribute file from a kobject
+ * @kobj: kobject the attribute is removed from
+ * @attr: attribute to be removed
+ */
+void kobject_remove_file(struct kobject *kobj, struct kobj_attribute *attr)
+{
+	sysfs_remove_file(kobj, &attr->attr);
+}
+EXPORT_SYMBOL_GPL(kobject_remove_file);
+
 static void dir_release(struct kobject *kobj)
 {
 	kfree(kobj);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux