Skip to content

Commit a90326c

Browse files
weiny2davejiang
authored andcommitted
cxl/region: Refactor common create region code
create_pmem_region_store() and create_ram_region_store() are identical with the exception of the region mode. With the addition of DC region mode this would end up being 3 copies of the same code. Refactor create_pmem_region_store() and create_ram_region_store() to use a single common function to be used in subsequent DC code. Suggested-by: Fan Ni <fan.ni@samsung.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Fan Ni <fan.ni@samsung.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Reviewed-by: Li Ming <ming4.li@intel.com> Reviewed-by: Alison Schofield <alison.schofield@intel.com> Signed-off-by: Ira Weiny <ira.weiny@intel.com> Link: https://patch.msgid.link/20241107-dcd-type2-upstream-v7-6-56a84e66bc36@intel.com Signed-off-by: Dave Jiang <dave.jiang@intel.com>
1 parent 27fcfb4 commit a90326c

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

drivers/cxl/core/region.c

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,9 +2536,8 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
25362536
return devm_cxl_add_region(cxlrd, id, mode, CXL_DECODER_HOSTONLYMEM);
25372537
}
25382538

2539-
static ssize_t create_pmem_region_store(struct device *dev,
2540-
struct device_attribute *attr,
2541-
const char *buf, size_t len)
2539+
static ssize_t create_region_store(struct device *dev, const char *buf,
2540+
size_t len, enum cxl_decoder_mode mode)
25422541
{
25432542
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev);
25442543
struct cxl_region *cxlr;
@@ -2548,31 +2547,26 @@ static ssize_t create_pmem_region_store(struct device *dev,
25482547
if (rc != 1)
25492548
return -EINVAL;
25502549

2551-
cxlr = __create_region(cxlrd, CXL_DECODER_PMEM, id);
2550+
cxlr = __create_region(cxlrd, mode, id);
25522551
if (IS_ERR(cxlr))
25532552
return PTR_ERR(cxlr);
25542553

25552554
return len;
25562555
}
2556+
2557+
static ssize_t create_pmem_region_store(struct device *dev,
2558+
struct device_attribute *attr,
2559+
const char *buf, size_t len)
2560+
{
2561+
return create_region_store(dev, buf, len, CXL_DECODER_PMEM);
2562+
}
25572563
DEVICE_ATTR_RW(create_pmem_region);
25582564

25592565
static ssize_t create_ram_region_store(struct device *dev,
25602566
struct device_attribute *attr,
25612567
const char *buf, size_t len)
25622568
{
2563-
struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev);
2564-
struct cxl_region *cxlr;
2565-
int rc, id;
2566-
2567-
rc = sscanf(buf, "region%d\n", &id);
2568-
if (rc != 1)
2569-
return -EINVAL;
2570-
2571-
cxlr = __create_region(cxlrd, CXL_DECODER_RAM, id);
2572-
if (IS_ERR(cxlr))
2573-
return PTR_ERR(cxlr);
2574-
2575-
return len;
2569+
return create_region_store(dev, buf, len, CXL_DECODER_RAM);
25762570
}
25772571
DEVICE_ATTR_RW(create_ram_region);
25782572

0 commit comments

Comments
 (0)