hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/base/class.c
....@@ -8,6 +8,7 @@
88 * Copyright (c) 2003-2004 IBM Corp.
99 */
1010
11
+#include <linux/device/class.h>
1112 #include <linux/device.h>
1213 #include <linux/module.h>
1314 #include <linux/init.h>
....@@ -117,16 +118,22 @@
117118 kset_put(&cls->p->subsys);
118119 }
119120
121
+static struct device *klist_class_to_dev(struct klist_node *n)
122
+{
123
+ struct device_private *p = to_device_private_class(n);
124
+ return p->device;
125
+}
126
+
120127 static void klist_class_dev_get(struct klist_node *n)
121128 {
122
- struct device *dev = container_of(n, struct device, knode_class);
129
+ struct device *dev = klist_class_to_dev(n);
123130
124131 get_device(dev);
125132 }
126133
127134 static void klist_class_dev_put(struct klist_node *n)
128135 {
129
- struct device *dev = container_of(n, struct device, knode_class);
136
+ struct device *dev = klist_class_to_dev(n);
130137
131138 put_device(dev);
132139 }
....@@ -185,6 +192,11 @@
185192 }
186193 error = class_add_groups(class_get(cls), cls->class_groups);
187194 class_put(cls);
195
+ if (error) {
196
+ kobject_del(&cp->subsys.kobj);
197
+ kfree_const(cp->subsys.kobj.name);
198
+ kfree(cp);
199
+ }
188200 return error;
189201 }
190202 EXPORT_SYMBOL_GPL(__class_register);
....@@ -277,7 +289,7 @@
277289 struct klist_node *start_knode = NULL;
278290
279291 if (start)
280
- start_knode = &start->knode_class;
292
+ start_knode = &start->p->knode_class;
281293 klist_iter_init_node(&class->p->klist_devices, &iter->ki, start_knode);
282294 iter->type = type;
283295 }
....@@ -304,7 +316,7 @@
304316 knode = klist_next(&iter->ki);
305317 if (!knode)
306318 return NULL;
307
- dev = container_of(knode, struct device, knode_class);
319
+ dev = klist_class_to_dev(knode);
308320 if (!iter->type || iter->type == dev->type)
309321 return dev;
310322 }
....@@ -471,7 +483,7 @@
471483 struct class_attribute_string *cs;
472484
473485 cs = container_of(attr, struct class_attribute_string, attr);
474
- return snprintf(buf, PAGE_SIZE, "%s\n", cs->str);
486
+ return sysfs_emit(buf, "%s\n", cs->str);
475487 }
476488
477489 EXPORT_SYMBOL_GPL(show_class_attr_string);