1、实现kobj_type的release函数
# include <linux/module.h>
# include <linux/init.h>
# include <linux/kernel.h>
# include <linux/kobject.h>
# include <linux/slab.h> static void dynamic_kobj_release ( struct kobject * kobj) ;
struct my_kobject
{ struct kobject kobj; int value;
} ;
struct my_kobject * my_kobject01; static struct kobj_type mytype = { . release = dynamic_kobj_release,
} ; static void dynamic_kobj_release ( struct kobject * kobj)
{ struct my_kobject * my_kobj = container_of ( kobj, struct my_kobject , kobj) ; printk ( "kobject: (%p): %s\n" , kobj, __func__ ) ; kfree ( my_kobj) ;
} static int my_kobject_init ( void )
{ int ret; my_kobject01 = kzalloc ( sizeof ( struct my_kobject ) , GFP_KERNEL) ; ret = kobject_init_and_add ( & my_kobject01-> kobj, & mytype, NULL , "%s" , "my_kobject01" ) ; return 0 ;
} static void