本文記錄leds_class的創建過程:
1.
static int __init leds_init(void)
{
leds_class = class_create(THIS_MODULE, "leds");
...
}
2.
/**
* class_create - create a struct class structure
* @owner: pointer to the module that is to "own" this struct class
* @name: pointer to a string for the name of this class.
*
* This is used to create a struct class pointer that can then be used
* in calls to class_device_create().
*
* Note, the pointer created here is to be destroyed when finished by
* making a call to class_destroy().
*/
struct class *class_create(struct module *owner, const char *name)
{
struct class *cls;
...
cls = kzalloc(sizeof(*cls), GFP_KERNEL);
...
cls->name = name;
cls->owner = owner;
cls->class_release = class_create_release;
cls->release = class_device_create_release;
retval = class_register(cls);
...
return cls;
...
}
3.
int class_register(struct class * cls)
{
...
error = kobject_set_name(&cls->subsys.kobj, "%s", cls->name);
...
subsys_set_kset(cls, class_subsys);
error = subsystem_register(&cls->subsys);
...
return error;
}
leds_class指針及class_subsys之間的關聯示意: