函数class_destroy()用于删除设备的逻辑类,即从Linux内核系统中删除设备的逻辑类。此函数执行的效果是删除函数__class_create()或宏class_create()在/sys/class/目录下创建的逻辑类对应的文件夹。
class_destroy()源码如下:
/**
* class_destroy - destroys a struct class structure
* @cls: pointer to the struct class that is to be destroyed
*
* Note, the pointer to be destroyed must have been created with a call
* to class_create().
*/
void class_destroy(struct class *cls)
{
if ((cls == NULL) || (IS_ERR(cls)))
return;
class_unregister(cls);
}
cls:struct class结构体类型的变量,代表通过class_create创建的设备的逻辑类。
通过分析源码可知,class_destroy调用了class_unregister()函数,它的具体实现如下:
void class_unregister(struct class *cls)
{
pr_debug("device class '%s': unregistering\n", cls->name);
class_remove_groups(cls, cls->class_groups);
kset_unregister(&cls->p->subsys);
}