@@ -74,10 +74,12 @@ static int create_dir(struct kobject *kobj)
74
74
if (error )
75
75
return error ;
76
76
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
+ }
81
83
}
82
84
83
85
/*
@@ -589,7 +591,8 @@ static void __kobject_del(struct kobject *kobj)
589
591
sd = kobj -> sd ;
590
592
ktype = get_ktype (kobj );
591
593
592
- sysfs_remove_groups (kobj , ktype -> default_groups );
594
+ if (ktype )
595
+ sysfs_remove_groups (kobj , ktype -> default_groups );
593
596
594
597
/* send "remove" if the caller did not do it but sent "add" */
595
598
if (kobj -> state_add_uevent_sent && !kobj -> state_remove_uevent_sent ) {
@@ -666,6 +669,10 @@ static void kobject_cleanup(struct kobject *kobj)
666
669
pr_debug ("'%s' (%p): %s, parent %p\n" ,
667
670
kobject_name (kobj ), kobj , __func__ , kobj -> parent );
668
671
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
+
669
676
/* remove from sysfs if the caller did not do it */
670
677
if (kobj -> state_in_sysfs ) {
671
678
pr_debug ("'%s' (%p): auto cleanup kobject_del\n" ,
@@ -676,13 +683,10 @@ static void kobject_cleanup(struct kobject *kobj)
676
683
parent = NULL ;
677
684
}
678
685
679
- if (t -> release ) {
686
+ if (t && t -> release ) {
680
687
pr_debug ("'%s' (%p): calling ktype release\n" ,
681
688
kobject_name (kobj ), kobj );
682
689
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 );
686
690
}
687
691
688
692
/* free name if we allocated it */
@@ -1056,7 +1060,7 @@ const struct kobj_ns_type_operations *kobj_child_ns_ops(const struct kobject *pa
1056
1060
{
1057
1061
const struct kobj_ns_type_operations * ops = NULL ;
1058
1062
1059
- if (parent && parent -> ktype -> child_ns_type )
1063
+ if (parent && parent -> ktype && parent -> ktype -> child_ns_type )
1060
1064
ops = parent -> ktype -> child_ns_type (parent );
1061
1065
1062
1066
return ops ;
0 commit comments