Skip to content

Commit 3ca8fba

Browse files
committed
Revert "kobject: Remove redundant checks for whether ktype is NULL"
This reverts commit 1b28cb8. It is reported to cause problems, so revert it for now until the root cause can be found. Reported-by: kernel test robot <oliver.sang@intel.com> Fixes: 1b28cb8 ("kobject: Remove redundant checks for whether ktype is NULL") Cc: Zhen Lei <thunder.leizhen@huawei.com> Closes: https://lore.kernel.org/oe-lkp/202402071403.e302e33a-oliver.sang@intel.com Link: https://lore.kernel.org/r/2024020849-consensus-length-6264@gregkh Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6e7ad1a commit 3ca8fba

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lib/kobject.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)