Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751814AbbFHC2m (ORCPT ); Sun, 7 Jun 2015 22:28:42 -0400 Received: from e23smtp04.au.ibm.com ([202.81.31.146]:34747 "EHLO e23smtp04.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751081AbbFHC2d (ORCPT ); Sun, 7 Jun 2015 22:28:33 -0400 Date: Mon, 8 Jun 2015 10:26:23 +0800 From: Wei Yang To: Greg KH Cc: Wei Yang , linux-kernel@vger.kernel.org Subject: Re: [PATCH] kobject: avoid unnecessary assignment of kobj->parent Message-ID: <20150608022623.GA6441@richard> Reply-To: Wei Yang References: <1433384030-16039-1-git-send-email-weiyang@linux.vnet.ibm.com> <20150606042230.GA15748@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150606042230.GA15748@kroah.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15060802-0013-0000-0000-000001648FDE Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2128 Lines: 63 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 >> --- >> 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/