* [PATCH] kobject: avoid unnecessary assignment of kobj->parent
@ 2015-06-04 2:13 Wei Yang
2015-06-06 4:22 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Wei Yang @ 2015-06-04 2:13 UTC (permalink / raw)
To: gregkh; +Cc: linux-kernel, Wei Yang
kobj->parent is changed only when it is NULL originally.
This patch moves the assignment in the "if" to avoid unnecessary assignment.
Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
---
lib/kobject.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/lib/kobject.c b/lib/kobject.c
index 03d4ab3..37b10bb 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -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",
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] kobject: avoid unnecessary assignment of kobj->parent
2015-06-04 2:13 [PATCH] kobject: avoid unnecessary assignment of kobj->parent Wei Yang
@ 2015-06-06 4:22 ` Greg KH
2015-06-08 2:26 ` Wei Yang
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2015-06-06 4:22 UTC (permalink / raw)
To: Wei Yang; +Cc: linux-kernel
On Thu, Jun 04, 2015 at 10:13:50AM +0800, Wei Yang wrote:
> kobj->parent is changed only when it is NULL originally.
>
> This patch moves the assignment in the "if" to avoid unnecessary assignment.
>
> Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
> ---
> lib/kobject.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/lib/kobject.c b/lib/kobject.c
> index 03d4ab3..37b10bb 100644
> --- a/lib/kobject.c
> +++ b/lib/kobject.c
> @@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] kobject: avoid unnecessary assignment of kobj->parent
2015-06-06 4:22 ` Greg KH
@ 2015-06-08 2:26 ` Wei Yang
0 siblings, 0 replies; 3+ messages in thread
From: Wei Yang @ 2015-06-08 2:26 UTC (permalink / raw)
To: Greg KH; +Cc: Wei Yang, linux-kernel
On Sat, Jun 06, 2015 at 01:22:30PM +0900, Greg KH wrote:
>On Thu, Jun 04, 2015 at 10:13:50AM +0800, Wei Yang wrote:
>> kobj->parent is changed only when it is NULL originally.
>>
>> This patch moves the assignment in the "if" to avoid unnecessary assignment.
>>
>> Signed-off-by: Wei Yang <weiyang@linux.vnet.ibm.com>
>> ---
>> lib/kobject.c | 3 +--
>> 1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/lib/kobject.c b/lib/kobject.c
>> index 03d4ab3..37b10bb 100644
>> --- a/lib/kobject.c
>> +++ b/lib/kobject.c
>> @@ -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;
>greg k-h
--
Richard Yang
Help you, Help me
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-06-08 2:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-04 2:13 [PATCH] kobject: avoid unnecessary assignment of kobj->parent Wei Yang
2015-06-06 4:22 ` Greg KH
2015-06-08 2:26 ` Wei Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox