Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

driver core: class: add class_groups support

struct class needs to have a set of default groups that are added, as
adding individual attributes does not work well in the long run. So add
support for that.

Future patches will convert the existing usages of class_attrs to use
class_groups and then class_attrs will go away.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

+17
+15
drivers/base/class.c
··· 163 163 put_device(dev); 164 164 } 165 165 166 + static int class_add_groups(struct class *cls, 167 + const struct attribute_group **groups) 168 + { 169 + return sysfs_create_groups(&cls->p->subsys.kobj, groups); 170 + } 171 + 172 + static void class_remove_groups(struct class *cls, 173 + const struct attribute_group **groups) 174 + { 175 + return sysfs_remove_groups(&cls->p->subsys.kobj, groups); 176 + } 177 + 166 178 int __class_register(struct class *cls, struct lock_class_key *key) 167 179 { 168 180 struct subsys_private *cp; ··· 215 203 kfree(cp); 216 204 return error; 217 205 } 206 + error = class_add_groups(class_get(cls), cls->class_groups); 207 + class_put(cls); 218 208 error = add_class_attrs(class_get(cls)); 219 209 class_put(cls); 220 210 return error; ··· 227 213 { 228 214 pr_debug("device class '%s': unregistering\n", cls->name); 229 215 remove_class_attrs(cls); 216 + class_remove_groups(cls, cls->class_groups); 230 217 kset_unregister(&cls->p->subsys); 231 218 } 232 219
+2
include/linux/device.h
··· 362 362 * @name: Name of the class. 363 363 * @owner: The module owner. 364 364 * @class_attrs: Default attributes of this class. 365 + * @class_groups: Default attributes of this class. 365 366 * @dev_groups: Default attributes of the devices that belong to the class. 366 367 * @dev_kobj: The kobject that represents this class and links it into the hierarchy. 367 368 * @dev_uevent: Called when a device is added, removed from this class, or a ··· 391 390 struct module *owner; 392 391 393 392 struct class_attribute *class_attrs; 393 + const struct attribute_group **class_groups; 394 394 const struct attribute_group **dev_groups; 395 395 struct kobject *dev_kobj; 396 396