Re: [PATCH v2 7/7] cxl/region: Drop goto pattern of construct_region()

From: Dan Williams
Date: Wed Feb 19 2025 - 20:05:53 EST


Li Ming wrote:
> Some operations need to be protected by the cxl_region_rwsem in
> construct_region(). Currently, construct_region() uses down_write() and
> up_write() for the cxl_region_rwsem locking, so there is a goto pattern
> after down_write() invoked to release cxl_region_rwsem.
>
> construct region() can be optimized to remove the goto pattern. The
> changes are creating a new function called construct_auto_region() which
> will include all checking and operations protected by the
> cxl_region_rwsem, and using guard(rwsem_write) to replace down_write()
> and up_write() in construct_auto_region().
>
> Signed-off-by: Li Ming <ming.li@xxxxxxxxxxxx>
> ---
> v2:
> - Rename __construct_region() to construct_auto_region(). (Jonathan and Dave)
> ---
> drivers/cxl/core/region.c | 71 +++++++++++++++++++++------------------
> 1 file changed, 39 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 320a3f218131..7a9e51aba9f4 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -3216,49 +3216,31 @@ static int match_region_by_range(struct device *dev, const void *data)
> return 0;
> }
>
> -/* Establish an empty region covering the given HPA range */
> -static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,
> - struct cxl_endpoint_decoder *cxled)
> +static int construct_auto_region(struct cxl_region *cxlr,

...probably would have called this __construct_region() since there is
little distinction that merits adding the "auto" qualifier.

Other than that, for this and the others you can add:

Reviewed-by: Dan Williams <dan.j.williams@xxxxxxxxx>