Re: [PATCH v1 1/7] cxl/core: Use guard() to replace open-coded down_read/write()

From: Li Ming
Date: Wed Feb 12 2025 - 01:38:15 EST


On 2/12/2025 1:26 AM, Jonathan Cameron wrote:
> On Tue, 11 Feb 2025 15:57:21 +0800
> Li Ming <ming.li@xxxxxxxxxxxx> wrote:
>
>> Some down/up_read() and down/up_write() cases can be replaced by a
>> guard() simply to drop explicit unlock invoked. It helps to align coding
>> style with current CXL subsystem's.
>>
>> Signed-off-by: Li Ming <ming.li@xxxxxxxxxxxx>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
>
> I wondered if it was worth doing some early returns and dropping
> local variables, but on balance think it isn't worth doing.
>
>
>> @@ -364,10 +362,9 @@ resource_size_t cxl_dpa_size(struct cxl_endpoint_decoder *cxled)
>> {
>> resource_size_t size = 0;
>>
>> - down_read(&cxl_dpa_rwsem);
>> + guard(rwsem_read)(&cxl_dpa_rwsem);
>> if (cxled->dpa_res)
>> size = resource_size(cxled->dpa_res);
> Could return resource_size() here and return 0 below.
> I'm not sure it gains us much though.

Right, I will do it in V2.


>> - up_read(&cxl_dpa_rwsem);
>>
>> return size;
>> }
>> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
>> index e8d11a988fd9..e3bb33109ced 100644
>> --- a/drivers/cxl/core/region.c
>> +++ b/drivers/cxl/core/region.c
>> @@ -3216,10 +3216,9 @@ static int match_region_by_range(struct device *dev, const void *data)
>> cxlr = to_cxl_region(dev);
>> p = &cxlr->params;
>>
>> - down_read(&cxl_region_rwsem);
>> + guard(rwsem_read)(&cxl_region_rwsem);
>> if (p->res && p->res->start == r->start && p->res->end == r->end)
>> rc = 1;
> could do return 1 here and return 0 but it doesn't gain us much.

Will do it in V2. thanks for review.


Ming

>
>> - up_read(&cxl_region_rwsem);
>>
>> return rc;
>> }
>