Skip to content

Commit

Permalink
sysfs: Add attribute array to sysdev classes
Browse files Browse the repository at this point in the history
Add a attribute array that is automatically registered and unregistered
to struct sysdev_class. This is similar to what struct class has.

A lot of drivers add list of attributes, so it's better to do 
this easily in the common sysdev layer.

This adds a new field to struct sysdev_class. I audited the 
whole tree and there are no dynamically allocated sysdev classes,
so this is fully compatible. 

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Andi Kleen authored and Greg Kroah-Hartman committed Mar 8, 2010
1 parent 1c205ae commit 38457ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drivers/base/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,20 @@ int sysdev_class_register(struct sysdev_class *cls)
if (retval)
return retval;

return kset_register(&cls->kset);
retval = kset_register(&cls->kset);
if (!retval && cls->attrs)
retval = sysfs_create_files(&cls->kset.kobj,
(const struct attribute **)cls->attrs);
return retval;
}

void sysdev_class_unregister(struct sysdev_class *cls)
{
pr_debug("Unregistering sysdev class '%s'\n",
kobject_name(&cls->kset.kobj));
if (cls->attrs)
sysfs_remove_files(&cls->kset.kobj,
(const struct attribute **)cls->attrs);
kset_unregister(&cls->kset);
}

Expand Down
2 changes: 2 additions & 0 deletions include/linux/sysdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@


struct sys_device;
struct sysdev_class_attribute;

struct sysdev_class {
const char *name;
struct list_head drivers;
struct sysdev_class_attribute **attrs;

/* Default operations for these types of devices */
int (*shutdown)(struct sys_device *);
Expand Down

0 comments on commit 38457ab

Please sign in to comment.