[PATCH] kobject: kobject_add_internal cleanup

From: Qiao Yanbo
Date: Tue Jul 27 2021 - 10:32:48 EST


From: qiaoyanbo <qiaoyanbo_310@xxxxxxx>

parent assignment in "if" block only need to consider when parent is NULL.

Signed-off-by: qiaoyanbo <qiaoyanbo_310@xxxxxxx>
---
lib/kobject.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/kobject.c b/lib/kobject.c
index ea53b30cf..d1f4b3411 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -241,10 +241,11 @@ static int kobject_add_internal(struct kobject *kobj)

/* join kset if set, use it as parent if we do not already have one */
if (kobj->kset) {
- if (!parent)
+ if (!parent) {
parent = kobject_get(&kobj->kset->kobj);
+ kobj->parent = parent;
+ }
kobj_kset_join(kobj);
- kobj->parent = parent;
}

pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
--
2.30.2