kobject: avoid unnecessary assignment of kobj->parent
Subsystems (2)
PATCH 1/1 kobject: avoid unnecessary assignment of kobj->parent
kobj->parent is changed only when it is NULL originally.
This patch moves the assignment in the "if" to avoid unnecessary assignment.
--- lib/kobject.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/kobject.c +1 -2
@@ -216,9 +216,8 @@ 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) - parent =kobject_get (&kobj->kset->kobj); + parent = kobj->parent =kobject_get (&kobj->kset->kobj);kobj_kset_join (kobj); - kobj->parent = parent; } pr_debug("kobject: '%s' (%p): %s: parent: '%s', set: '%s'\n",
Signature · 1 line
1.7.9.5
Greg KH
maintainerQuoted 14 lines · Wei Yang
kobj->parentis changed only when it is NULL originally.This patch moves the assignment in the "if" to avoid unnecessary assignment.
Signed-off-by Wei Yang <[email protected]>--- lib/kobject.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)lib/kobject.c +0
-0
lib/kobject.c static int kobject_add_internal(struct kobject *kobj) · line 221
Quoted 7 lines
lib/kobject.c +1
-2@@ -216,9 +216,8 @@ 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) - parent =kobject_get (&kobj->kset->kobj); + parent = kobj->parent =kobject_get (&kobj->kset->kobj);kobj_kset_join (kobj); - kobj->parent = parent;
What is this "fixing"? I hate multiple assignments on the same line, it makes it harder to read and understand.
greg k-h
Quoted 10 lines · Greg KH
Quoted 9 lines · Wei Yang
kobj->parentis changed only when it is NULL originally.This patch moves the assignment in the "if" to avoid unnecessary assignment.
Signed-off-by Wei Yang <[email protected]>--- lib/kobject.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 16 lines
lib/kobject.c static int kobject_add_internal(struct kobject *kobj) · line 221
Quoted 12 lines
lib/kobject.c +1
-2@@ -216,9 +216,8 @@ 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) - parent =kobject_get (&kobj->kset->kobj); + parent = kobj->parent =kobject_get (&kobj->kset->kobj);kobj_kset_join (kobj); - kobj->parent = parent;What is this "fixing"? I hate multiple assignments on the same line, it makes it harder to read and understand.
Hi Greg
No. This one is not "fixing" anything. What it does is to not assign the kobj->parent again when it is not changed.
No, this is not a "fixing". So it doesn't help on the functionality or improve the performance. It just wants to make it clear that the kobj->parent is changed when originally it is NULL, not for other cases. Hope this would help a little.
I didn't noticed that you don't like this format, so I didn't want to offend you intendedly. How about move "kobj->parent = parent" above and add a brace to the if? For example like this:
/* 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;
Quoted 1 line
greg k-h
Signature · 2 lines
Richard Yang Help you, Help me