[PATCH 4/7] EDAC/aspeed: Free the mem_ctl_info unconditionally on remove

From: Ryan Chen

Date: Wed Aug 12 2026 - 01:50:37 EST


aspeed_remove() is a driver .remove callback, so it only runs for a device
that has already probed successfully and registered its mem_ctl_info. In
that case edac_mc_del_mc() always returns the same, valid pointer, and the
NULL check on its return value can never be false.

Fetch the mem_ctl_info from the platform device's driver data instead and
free it unconditionally, dropping the redundant check. This also decouples
the teardown from the return value of edac_mc_del_mc().

Signed-off-by: Ryan Chen <ryan_chen@xxxxxxxxxxxxxx>
---
drivers/edac/aspeed_edac.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/edac/aspeed_edac.c b/drivers/edac/aspeed_edac.c
index 71535e0b6bad..8bfeb21d3204 100644
--- a/drivers/edac/aspeed_edac.c
+++ b/drivers/edac/aspeed_edac.c
@@ -343,16 +343,15 @@ static int aspeed_probe(struct platform_device *pdev)

static void aspeed_remove(struct platform_device *pdev)
{
- struct mem_ctl_info *mci;
+ struct mem_ctl_info *mci = platform_get_drvdata(pdev);

/* disable interrupts */
regmap_update_bits(aspeed_regmap, ASPEED_MCR_INTR_CTRL,
ASPEED_MCR_INTR_CTRL_ENABLE, 0);

/* free resources */
- mci = edac_mc_del_mc(&pdev->dev);
- if (mci)
- edac_mc_free(mci);
+ edac_mc_del_mc(&pdev->dev);
+ edac_mc_free(mci);
}

static const struct of_device_id aspeed_of_match[] = {

--
2.34.1