All of lore.kernel.org
 help / color / mirror / Atom feed
From: quic_zijuhu <quic_zijuhu@quicinc.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: <linux-kernel@vger.kernel.org>, <rafael@kernel.org>,
	<madalin.bucur@nxp.com>
Subject: Re: [PATCH v1 4/5] devres: Simplify devm_percpu_match() implementation
Date: Mon, 8 Jul 2024 21:50:48 +0800	[thread overview]
Message-ID: <12e5dade-8ef3-4532-aff6-b78b87dc0147@quicinc.com> (raw)
In-Reply-To: <4ecbe215-6b73-48ea-8e8d-831e3682754c@quicinc.com>

On 7/4/2024 9:17 PM, quic_zijuhu wrote:
> On 7/4/2024 6:34 PM, Greg KH wrote:
>> On Tue, Jul 02, 2024 at 10:51:53PM +0800, Zijun Hu wrote:
>>> Simplify devm_percpu_match() implementation by removing redundant
>>> conversions.
>>>
>>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
>>> ---
>>> Previous discussion link:
>>> https://lore.kernel.org/lkml/1719496036-24642-1-git-send-email-quic_zijuhu@quicinc.com/
>>>
>>> Changes since the original one:
>>>  - Select the simplier solution
>>>
>>>  drivers/base/devres.c | 5 ++---
>>>  1 file changed, 2 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
>>> index e9b0d94aeabd..2ad6dacb3472 100644
>>> --- a/drivers/base/devres.c
>>> +++ b/drivers/base/devres.c
>>> @@ -1176,9 +1176,8 @@ 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);
>>> -
>>> -	return *(void **)devr->data == p;
>>> +	/* @data is already and must be (void *)devr->data */
>>> +	return *(void **)data == p;
>>
>> The compiler output should be identical here, right?  And container_of()
> yes, you are right.
>> enforces the placement so I'd prefer the original here as a comment
>> isn't going to enforce anything :)
>>
> i would like to show 2 different points related to the comments below:
> 
> 1) the comments is applicable for *ALL* kinds of devres match()s, and is
> *NOT* specific to devm_percpu_match() and also does *NOT* enforce anything.
> 
> may i remove the comments?
> 
> 2) the original implementation is *NOT* normative as explained below:
> include/linux/device.h:
> typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
> void *devres_find(struct device *dev, dr_release_t release,
> 		  dr_match_t match, void *match_data);
> 
> devres API users maybe need to write their match() functions, for
> example, user of API devres_find(), but struct devres is a devres
> internal implementation defined within devres.c and is *NOT* exposed to
> API user by device.h, so API user should not use struct devres when
> implement their devres match() normally.
> but original devm_percpu_match() uses the struct devres.
> 

thanks for your code review.
may i know which of below options is your final preference?

A) remain current kernel design, namely, no changes.

B) changes shown by this [PATCH v1 4/5]

C) below changes we ever discussed by below link
https://lore.kernel.org/all/1719496036-24642-1-git-send-email-quic_zijuhu@quicinc.com/

 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;
 }

>> thanks,
>>
>> greg k-h
> 


  reply	other threads:[~2024-07-08 13:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-02 14:51 [PATCH v1 0/5] Collection of my bug fixes and code optimizations for devres Zijun Hu
2024-07-02 14:51 ` [PATCH v1 1/5] devres: Fix devm_krealloc() wasting memory Zijun Hu
2024-07-02 14:51 ` [PATCH v1 2/5] devres: Fix memory leakage caused by driver API devm_free_percpu() Zijun Hu
2024-07-02 14:51 ` [PATCH v1 3/5] devres: Initialize an uninitialized struct member Zijun Hu
2024-07-02 14:51 ` [PATCH v1 4/5] devres: Simplify devm_percpu_match() implementation Zijun Hu
2024-07-04 10:34   ` Greg KH
2024-07-04 13:17     ` quic_zijuhu
2024-07-08 13:50       ` quic_zijuhu [this message]
2024-07-02 14:51 ` [PATCH v1 5/5] devres: Correct code style for functions that return a pointer type Zijun Hu

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=12e5dade-8ef3-4532-aff6-b78b87dc0147@quicinc.com \
    --to=quic_zijuhu@quicinc.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=madalin.bucur@nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.