Re: [PATCH v1 07/29] cxl/region: Factor out code to find a root decoder's region
From: Robert Richter
Date: Thu Jan 30 2025 - 11:44:36 EST
On Tue, Jan 07, 2025 at 11:59:43AM -0500, Gregory Price wrote:
> On Tue, Jan 07, 2025 at 03:09:53PM +0100, Robert Richter wrote:
> > In function cxl_add_to_region() there is code to determine a root
> > decoder's region. Factor that code out. This is in preparation to
> > further rework and simplify function cxl_add_to_region().
> >
> > No functional changes.
> >
> > Signed-off-by: Robert Richter <rrichter@xxxxxxx>
> > ---
> > drivers/cxl/core/region.c | 24 ++++++++++++++++--------
> > 1 file changed, 16 insertions(+), 8 deletions(-)
> >
> ... snip ...
> > * one does the construction and the others add to that.
> > */
> > mutex_lock(&cxlrd->range_lock);
>
> If the function must be called with the cxlrd range lock held, then the
> function should have a comment/contract that states this.
No, the mutex locks the check for cxlr and construct_region().
cxl_find_region_by_range() itself doesn't need a lock.
-Robert
>
> > - region_dev = device_find_child(&cxlrd->cxlsd.cxld.dev, hpa,
> > - match_region_by_range);
> > - if (!region_dev) {
> > + cxlr = cxl_find_region_by_range(cxlrd, hpa);
> > + if (!cxlr)
> > cxlr = construct_region(cxlrd, cxled);
> > - region_dev = &cxlr->dev;
> > - } else
> > - cxlr = to_cxl_region(region_dev);
> > mutex_unlock(&cxlrd->range_lock);
> >