[PATCH v9 1/3] cxl/region: Simplify poison_by_decoder() error handling
From: Richard Cheng
Date: Wed Aug 05 2026 - 01:56:37 EST
"rc" carries both an error code and the loop control
signal for device_for_each_child(), so returning it bare is misleading,
the early guards mean "keep walking", not "no error". Zeroing "rc" to
forgive an -EFAULT on a RAM partition adds to that by discarding what
the device actually returned.
Return a literal 0 where the walk should continue, and test the
forgiven case directly instead of rewriting "rc". Give that test a
name, poison_efault_forgiven(), so cxl_get_poison_unmapped() and
poison_by_decoder() spell the same rule the same way. No functional
change.
Suggested-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
Signed-off-by: Richard Cheng <icheng@xxxxxxxxxx>
Reviewed-by: Alison Schofield <alison.schofield@xxxxxxxxx>
---
Changelog:
v8 -> v9:
- Add the poison_efault_forgiven() helper and use it in
cxl_get_poison_unmapped()
v7 -> v8:
- New patch. Splits the poison_by_decoder() readability cleanup out
of "cxl/hdm: Allow zero sized HDM decoders" so the functional
change is not mixed with a refactor of pre-existing code.
---
drivers/cxl/core/region.c | 26 ++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 1e211542b6b6..45536909cc17 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -2905,6 +2905,16 @@ struct cxl_poison_context {
u64 offset;
};
+/*
+ * A device may answer a Get Poison List request with "physical address
+ * specified is invalid" (-EFAULT). That answer is tolerated for a RAM
+ * partition and the poison walk continues.
+ */
+static inline bool poison_efault_forgiven(int rc, enum cxl_partition_mode mode)
+{
+ return rc == -EFAULT && mode == CXL_PARTMODE_RAM;
+}
+
static int cxl_get_poison_unmapped(struct cxl_memdev *cxlmd,
struct cxl_poison_context *ctx)
{
@@ -2933,7 +2943,7 @@ static int cxl_get_poison_unmapped(struct cxl_memdev *cxlmd,
if (!length)
break;
rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
- if (rc == -EFAULT && cxlds->part[i].mode == CXL_PARTMODE_RAM)
+ if (poison_efault_forgiven(rc, cxlds->part[i].mode))
continue;
if (rc)
break;
@@ -2950,14 +2960,14 @@ static int poison_by_decoder(struct device *dev, void *arg)
struct cxl_dev_state *cxlds;
struct cxl_memdev *cxlmd;
u64 offset, length;
- int rc = 0;
+ int rc;
if (!is_endpoint_decoder(dev))
- return rc;
+ return 0;
cxled = to_cxl_endpoint_decoder(dev);
if (!cxled->dpa_res)
- return rc;
+ return 0;
cxlmd = cxled_to_memdev(cxled);
cxlds = cxlmd->cxlds;
@@ -2967,18 +2977,14 @@ static int poison_by_decoder(struct device *dev, void *arg)
offset = cxled->dpa_res->start - cxled->skip;
length = cxled->skip;
rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
- if (rc == -EFAULT && mode == CXL_PARTMODE_RAM)
- rc = 0;
- if (rc)
+ if (rc && !poison_efault_forgiven(rc, mode))
return rc;
}
offset = cxled->dpa_res->start;
length = cxled->dpa_res->end - offset + 1;
rc = cxl_mem_get_poison(cxlmd, offset, length, cxled->cxld.region);
- if (rc == -EFAULT && mode == CXL_PARTMODE_RAM)
- rc = 0;
- if (rc)
+ if (rc && !poison_efault_forgiven(rc, mode))
return rc;
/* Iterate until commit_end is reached */
--
2.43.0