[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250715191143.1023512-4-rrichter@amd.com>
Date: Tue, 15 Jul 2025 21:11:26 +0200
From: Robert Richter <rrichter@....com>
To: Alison Schofield <alison.schofield@...el.com>, Vishal Verma
	<vishal.l.verma@...el.com>, Ira Weiny <ira.weiny@...el.com>, Dan Williams
	<dan.j.williams@...el.com>, Jonathan Cameron <Jonathan.Cameron@...wei.com>,
	Dave Jiang <dave.jiang@...el.com>, Davidlohr Bueso <dave@...olabs.net>
CC: <linux-cxl@...r.kernel.org>, <linux-kernel@...r.kernel.org>, Gregory Price
	<gourry@...rry.net>, "Fabio M. De Francesco"
	<fabio.m.de.francesco@...ux.intel.com>, Terry Bowman <terry.bowman@....com>,
	Robert Richter <rrichter@....com>
Subject: [PATCH v1 03/20] cxl/region: Remove region id handling from cxl_region_alloc()
The region's id is not needed to allocate the region. Move the region
id handling out of cxl_region_alloc(). This simplifies the function
interface and allows the implementation of an early region allocation
when an id is not yet assigned.
Signed-off-by: Robert Richter <rrichter@....com>
---
 drivers/cxl/core/region.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index a18ab5e30138..b968050ad3d7 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -2449,16 +2449,14 @@ static int cxl_region_calculate_adistance(struct notifier_block *nb,
 
 static struct lock_class_key cxl_region_key;
 
-static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int id)
+static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd)
 {
 	struct cxl_region *cxlr;
 	struct device *dev;
 
 	cxlr = kzalloc(sizeof(*cxlr), GFP_KERNEL);
-	if (!cxlr) {
-		memregion_free(id);
+	if (!cxlr)
 		return ERR_PTR(-ENOMEM);
-	}
 
 	dev = &cxlr->dev;
 	device_initialize(dev);
@@ -2474,7 +2472,6 @@ static struct cxl_region *cxl_region_alloc(struct cxl_root_decoder *cxlrd, int i
 	device_set_pm_not_required(dev);
 	dev->bus = &cxl_bus_type;
 	dev->type = &cxl_region_type;
-	cxlr->id = id;
 
 	return cxlr;
 }
@@ -2522,13 +2519,18 @@ static struct cxl_region *devm_cxl_add_region(struct cxl_root_decoder *cxlrd,
 	struct device *dev;
 	int rc;
 
-	cxlr = cxl_region_alloc(cxlrd, id);
-	if (IS_ERR(cxlr))
+	cxlr = cxl_region_alloc(cxlrd);
+	if (IS_ERR(cxlr)) {
+		memregion_free(id);
 		return cxlr;
+	}
+
 	cxlr->mode = mode;
 	cxlr->type = type;
 
 	dev = &cxlr->dev;
+	cxlr->id = id;
+
 	rc = dev_set_name(dev, "region%d", id);
 	if (rc)
 		goto err;
-- 
2.39.5
Powered by blists - more mailing lists
 
