Re: [PATCH] devres: Simple code optimization

From: quic_zijuhu
Date: Thu Jun 27 2024 - 10:30:02 EST


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@xxxxxxxxxxx>
>> ---
>> This change is intend to replace below one:
>> https://lore.kernel.org/lkml/1718629765-32720-1-git-send-email-quic_zijuhu@xxxxxxxxxxx/#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.
2) compare with right data type
original type of @p is void __percpu * returned by
__devm_alloc_percpu().

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

> And where did the container_of go? You just lost all type-safeness.
>
see above comments 1) and 2).
> thanks,
>
> greg k-h