@@ -74,10 +74,12 @@ static int create_dir(struct kobject *kobj)
7474 if (error )
7575 return error ;
7676
77- error = sysfs_create_groups (kobj , ktype -> default_groups );
78- if (error ) {
79- sysfs_remove_dir (kobj );
80- return error ;
77+ if (ktype ) {
78+ error = sysfs_create_groups (kobj , ktype -> default_groups );
79+ if (error ) {
80+ sysfs_remove_dir (kobj );
81+ return error ;
82+ }
8183 }
8284
8385 /*
@@ -589,7 +591,8 @@ static void __kobject_del(struct kobject *kobj)
589591 sd = kobj -> sd ;
590592 ktype = get_ktype (kobj );
591593
592- sysfs_remove_groups (kobj , ktype -> default_groups );
594+ if (ktype )
595+ sysfs_remove_groups (kobj , ktype -> default_groups );
593596
594597 /* send "remove" if the caller did not do it but sent "add" */
595598 if (kobj -> state_add_uevent_sent && !kobj -> state_remove_uevent_sent ) {
@@ -666,6 +669,10 @@ static void kobject_cleanup(struct kobject *kobj)
666669 pr_debug ("'%s' (%p): %s, parent %p\n" ,
667670 kobject_name (kobj ), kobj , __func__ , kobj -> parent );
668671
672+ if (t && !t -> release )
673+ pr_debug ("'%s' (%p): does not have a release() function, it is broken and must be fixed. See Documentation/core-api/kobject.rst.\n" ,
674+ kobject_name (kobj ), kobj );
675+
669676 /* remove from sysfs if the caller did not do it */
670677 if (kobj -> state_in_sysfs ) {
671678 pr_debug ("'%s' (%p): auto cleanup kobject_del\n" ,
@@ -676,13 +683,10 @@ static void kobject_cleanup(struct kobject *kobj)
676683 parent = NULL ;
677684 }
678685
679- if (t -> release ) {
686+ if (t && t -> release ) {
680687 pr_debug ("'%s' (%p): calling ktype release\n" ,
681688 kobject_name (kobj ), kobj );
682689 t -> release (kobj );
683- } else {
684- pr_debug ("'%s' (%p): does not have a release() function, it is broken and must be fixed. See Documentation/core-api/kobject.rst.\n" ,
685- kobject_name (kobj ), kobj );
686690 }
687691
688692 /* free name if we allocated it */
@@ -1056,7 +1060,7 @@ const struct kobj_ns_type_operations *kobj_child_ns_ops(const struct kobject *pa
10561060{
10571061 const struct kobj_ns_type_operations * ops = NULL ;
10581062
1059- if (parent && parent -> ktype -> child_ns_type )
1063+ if (parent && parent -> ktype && parent -> ktype -> child_ns_type )
10601064 ops = parent -> ktype -> child_ns_type (parent );
10611065
10621066 return ops ;
0 commit comments