Skip to content

Commit 1b28cb8

Browse files
Zhen Leigregkh
authored andcommitted
kobject: Remove redundant checks for whether ktype is NULL
When adding koject or kset, we have made sure that ktype cannot be NULL. Therefore, after adding koject or kset, there is no need to worry about ktype being NULL. Clear all ktype-related redundancy checks. Signed-off-by: Zhen Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4d0fe8c commit 1b28cb8

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

lib/kobject.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,10 @@ static int create_dir(struct kobject *kobj)
7474
if (error)
7575
return error;
7676

77-
if (ktype) {
78-
error = sysfs_create_groups(kobj, ktype->default_groups);
79-
if (error) {
80-
sysfs_remove_dir(kobj);
81-
return error;
82-
}
77+
error = sysfs_create_groups(kobj, ktype->default_groups);
78+
if (error) {
79+
sysfs_remove_dir(kobj);
80+
return error;
8381
}
8482

8583
/*
@@ -591,8 +589,7 @@ static void __kobject_del(struct kobject *kobj)
591589
sd = kobj->sd;
592590
ktype = get_ktype(kobj);
593591

594-
if (ktype)
595-
sysfs_remove_groups(kobj, ktype->default_groups);
592+
sysfs_remove_groups(kobj, ktype->default_groups);
596593

597594
/* send "remove" if the caller did not do it but sent "add" */
598595
if (kobj->state_add_uevent_sent && !kobj->state_remove_uevent_sent) {
@@ -669,10 +666,6 @@ static void kobject_cleanup(struct kobject *kobj)
669666
pr_debug("'%s' (%p): %s, parent %p\n",
670667
kobject_name(kobj), kobj, __func__, kobj->parent);
671668

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-
676669
/* remove from sysfs if the caller did not do it */
677670
if (kobj->state_in_sysfs) {
678671
pr_debug("'%s' (%p): auto cleanup kobject_del\n",
@@ -683,10 +676,13 @@ static void kobject_cleanup(struct kobject *kobj)
683676
parent = NULL;
684677
}
685678

686-
if (t && t->release) {
679+
if (t->release) {
687680
pr_debug("'%s' (%p): calling ktype release\n",
688681
kobject_name(kobj), kobj);
689682
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);
690686
}
691687

692688
/* free name if we allocated it */
@@ -1060,7 +1056,7 @@ const struct kobj_ns_type_operations *kobj_child_ns_ops(const struct kobject *pa
10601056
{
10611057
const struct kobj_ns_type_operations *ops = NULL;
10621058

1063-
if (parent && parent->ktype && parent->ktype->child_ns_type)
1059+
if (parent && parent->ktype->child_ns_type)
10641060
ops = parent->ktype->child_ns_type(parent);
10651061

10661062
return ops;

0 commit comments

Comments
 (0)