[PATCH v3 5/7] EDAC/versalnet: Make get_ddr_config() return errors
From: Shubhrajyoti Datta
Date: Fri Nov 27 2026 - 11:39:24 EST
get_ddr_config() invokes cdx_mcdi_rpc() but ignores its return value,
and proceeds even if the cdx_mcdi_rpc() returned errors. Also it
copies the data out of the response buffer without checking that
the firmware actually returned that much data.
Make get_ddr_config() return an int: propagate cdx_mcdi_rpc()'s
return code on failure, and return -EIO if the response is shorter
than expected. Update mc_probe() to check the return value and bail
out through the existing error path on failure.
Fixes: d5fe2fec6c40 ("EDAC: Add a driver for the AMD Versal NET DDR controller")
Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xxxxxxx>
---
Changes in v3:
use sizeof outbuf
Add a print for the failure
Reorder the patch
Changes in v2:
New patch added to bailout if the cdx_mcdi_rpc fails.
drivers/edac/versalnet_edac.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/edac/versalnet_edac.c b/drivers/edac/versalnet_edac.c
index 8c3f8733c049..7d8b8f2ecaea 100644
--- a/drivers/edac/versalnet_edac.c
+++ b/drivers/edac/versalnet_edac.c
@@ -577,7 +577,7 @@ static const struct cdx_mcdi_ops mcdi_ops = {
.mcdi_request = mcdi_request,
};
-static void get_ddr_config(u32 index, u32 *buffer, struct cdx_mcdi *amd_mcdi)
+static int get_ddr_config(u32 index, u32 *buffer, struct cdx_mcdi *amd_mcdi)
{
size_t outlen;
int ret;
@@ -589,9 +589,15 @@ static void get_ddr_config(u32 index, u32 *buffer, struct cdx_mcdi *amd_mcdi)
ret = cdx_mcdi_rpc(amd_mcdi, MC_CMD_EDAC_GET_DDR_CONFIG, inbuf, sizeof(inbuf),
outbuf, sizeof(outbuf), &outlen);
- if (!ret)
- memcpy(buffer, MCDI_PTR(outbuf, GET_DDR_CONFIG),
- (ADEC_NUM * 4));
+ if (ret)
+ return ret;
+
+ if (outlen < sizeof(outbuf))
+ return -EIO;
+
+ memcpy(buffer, MCDI_PTR(outbuf, GET_DDR_CONFIG), (ADEC_NUM * 4));
+
+ return 0;
}
static int setup_mcdi(struct mc_priv *mc_priv)
@@ -1030,8 +1036,13 @@ static int mc_probe(struct platform_device *pdev)
priv->mcdi->r5_rproc = rp;
- for (i = 0; i < NUM_CONTROLLERS; i++)
- get_ddr_config(i, &priv->adec[ADEC_NUM * i], priv->mcdi);
+ for (i = 0; i < NUM_CONTROLLERS; i++) {
+ rc = get_ddr_config(i, &priv->adec[ADEC_NUM * i], priv->mcdi);
+ if (rc) {
+ dev_err(&pdev->dev, "Failed to get DDR configuration\n");
+ goto err_init;
+ }
+ }
rc = init_versalnet(priv, pdev);
if (rc)
--
2.34.1