public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: quic_zijuhu <quic_zijuhu@quicinc.com>
Cc: rafael@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] devres: Simple code optimization
Date: Thu, 27 Jun 2024 16:35:40 +0200	[thread overview]
Message-ID: <2024062724-bunion-swept-23b9@gregkh> (raw)
In-Reply-To: <179b5505-f64b-4c29-b2df-2eec9e276904@quicinc.com>

On Thu, Jun 27, 2024 at 10:29:43PM +0800, quic_zijuhu wrote:
> On 6/27/2024 9:54 PM, Greg KH wrote:
> > On Thu, Jun 27, 2024 at 09:47:16PM +0800, Zijun Hu wrote:
> >> Initialize an uninitialized struct member for devres_open_group()
> >> and simplify devm_percpu_match() implementation.
> > 
> > Huge hint, when you say "and" or "also" in a patch, it's a good idea to
> > split it up into different commits, right?
> > 
> you are right.
> i would like to split this change into two changes within a patchset
> even if this change is *very* simple.
> >>
> >> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> >> ---
> >> This change is intend to replace below one:
> >> https://lore.kernel.org/lkml/1718629765-32720-1-git-send-email-quic_zijuhu@quicinc.com/#t
> > 
> > Why?  SHouldn't this be v2 instead?
> > 
> this change has different title and maybe be identified as different
> patch, so i send it as v1.
> >>  drivers/base/devres.c | 5 +++--
> >>  1 file changed, 3 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
> >> index 3df0025d12aa..5b1d498e83ab 100644
> >> --- a/drivers/base/devres.c
> >> +++ b/drivers/base/devres.c
> >> @@ -567,6 +567,7 @@ void * devres_open_group(struct device *dev, void *id, gfp_t gfp)
> >>  	grp->id = grp;
> >>  	if (id)
> >>  		grp->id = id;
> >> +	grp->color = 0;
> >>  
> >>  	spin_lock_irqsave(&dev->devres_lock, flags);
> >>  	add_dr(dev, &grp->node[0]);
> >> @@ -1172,9 +1173,9 @@ static void devm_percpu_release(struct device *dev, void *pdata)
> >>  
> >>  static int devm_percpu_match(struct device *dev, void *data, void *p)
> >>  {
> >> -	struct devres *devr = container_of(data, struct devres, data);
> >> +	void __percpu *ptr = *(void __percpu **)data;
> >>  
> >> -	return *(void **)devr->data == p;
> >> +	return ptr == (void __percpu *)p;
> > 
> > What exactly is being "optimized" here?
> > 
> 1) remove redundant container_of() and devr->data operations
>    pointer parameter @data already is address of devr->data.

But do we really know that ahead of time?  If so, how, just by virtue of
this being the first field?  If so, then no, keep the container_of.

> 2) compare with right data type
>     original type of @p is void __percpu * returned by
> __devm_alloc_percpu().

It's pointer math, no need for types, right?

> @data is storing a pointer type void __percpu * as shown by below
> statement within __devm_alloc_percpu().
> *(void __percpu **)p = pcpu;

Again, it's not very obvious so you better document the heck out of it
in your changelog text.

thanks,

greg k-h

  reply	other threads:[~2024-06-27 14:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-17 13:09 [PATCH v1] devres: Initialize a uninitialized struct member Zijun Hu
2024-06-17 18:14 ` Greg KH
2024-06-18 11:29   ` quic_zijuhu
2024-06-27 13:47     ` [PATCH] devres: Simple code optimization Zijun Hu
2024-06-27 13:54       ` Greg KH
2024-06-27 14:29         ` quic_zijuhu
2024-06-27 14:35           ` Greg KH [this message]
2024-06-27 15:13             ` quic_zijuhu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2024062724-bunion-swept-23b9@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quic_zijuhu@quicinc.com \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox