13 #include <linux/device.h>
14 #include <linux/module.h>
16 #include <linux/string.h>
17 #include <linux/kdev_t.h>
19 #include <linux/slab.h>
24 #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
34 ret = class_attr->
show(cp->
class, class_attr, buf);
45 if (class_attr->
store)
46 ret = class_attr->
store(cp->
class, class_attr, buf, count);
50 static const void *class_attr_namespace(
struct kobject *kobj,
62 static void class_release(
struct kobject *kobj)
70 class->class_release(
class);
72 pr_debug(
"class '%s' does not have a release() function, "
86 static const struct sysfs_ops class_sysfs_ops = {
87 .show = class_attr_show,
88 .store = class_attr_store,
89 .namespace = class_attr_namespace,
93 .sysfs_ops = &class_sysfs_ops,
94 .release = class_release,
95 .child_ns_type = class_child_ns_type,
99 static struct kset *class_kset;
119 static struct class *class_get(
struct class *cls)
122 kset_get(&cls->p->subsys);
126 static void class_put(
struct class *cls)
129 kset_put(&cls->p->subsys);
132 static int add_class_attrs(
struct class *cls)
137 if (cls->class_attrs) {
138 for (i = 0;
attr_name(cls->class_attrs[i]); i++) {
152 static void remove_class_attrs(
struct class *cls)
156 if (cls->class_attrs) {
157 for (i = 0;
attr_name(cls->class_attrs[i]); i++)
162 static void klist_class_dev_get(
struct klist_node *
n)
169 static void klist_class_dev_put(
struct klist_node *
n)
181 pr_debug(
"device class '%s': registering\n", cls->name);
200 #if defined(CONFIG_BLOCK)
203 cp->
subsys.kobj.kset = class_kset;
205 cp->
subsys.kobj.kset = class_kset;
207 cp->
subsys.kobj.ktype = &class_ktype;
216 error = add_class_attrs(class_get(cls));
224 pr_debug(
"device class '%s': unregistering\n", cls->name);
225 remove_class_attrs(cls);
229 static void class_create_release(
struct class *cls)
231 pr_debug(
"%s called for %s\n", __func__, cls->name);
273 return ERR_PTR(retval);
286 if ((cls ==
NULL) || (IS_ERR(cls)))
385 WARN(1,
"%s called for class '%s' before it was initialized",
392 error =
fn(dev, data);
432 WARN(1,
"%s called for class '%s' before it was initialized",
439 if (
match(dev, data)) {
456 if (!class_intf || !class_intf->
class)
459 parent = class_get(class_intf->
class);
468 class_intf->
add_dev(dev, class_intf);
486 list_del_init(&class_intf->
node);
554 struct device *device_link)
587 struct device *device_link)