When mc > 0, ie31200_register_mci() initializes priv->dev but fails to call put_device() on it in the error path, causing a memory leak. Add proper put_device() call for priv->dev in the error handling path to balance device_initialize().
Found by code review.
Cc: stable@vger.kernel.org Fixes: d0742284ec6d ("EDAC/ie31200: Add Intel Raptor Lake-S SoCs support") Signed-off-by: Ma Ke make24@iscas.ac.cn --- drivers/edac/ie31200_edac.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/edac/ie31200_edac.c b/drivers/edac/ie31200_edac.c index 5a080ab65476..a5a4bb24b72a 100644 --- a/drivers/edac/ie31200_edac.c +++ b/drivers/edac/ie31200_edac.c @@ -528,6 +528,8 @@ static int ie31200_register_mci(struct pci_dev *pdev, struct res_config *cfg, in fail_unmap: iounmap(window); fail_free: + if (mc > 0) + put_device(&priv->dev); edac_mc_free(mci); return ret; }
Hi Ma Ke,
Thanks for this report.
From: Ma Ke make24@iscas.ac.cn Sent: Tuesday, November 4, 2025 9:23 AM To: jbaron@akamai.com; bp@alien8.de; Luck, Tony tony.luck@intel.com; Zhuo, Qiuxu qiuxu.zhuo@intel.com Cc: linux-edac@vger.kernel.org; linux-kernel@vger.kernel.org; akpm@linux- foundation.org; Ma Ke make24@iscas.ac.cn; stable@vger.kernel.org Subject: [PATCH] EDAC/ie31200: Fix error handling in ie31200_register_mci
When mc > 0, ie31200_register_mci() initializes priv->dev but fails to call put_device() on it in the error path, causing a memory leak. Add proper
edac_mc_free() triggers mci_release(), which eventually frees mci->pvt_info, so there are no memory leaks, and put_device() is NOT needed.
put_device() call for priv->dev in the error handling path to balance device_initialize().
From the perspective of pairing with device_initialize() for better code readability, then we may add put_device().
Found by code review.
Cc: stable@vger.kernel.org Fixes: d0742284ec6d ("EDAC/ie31200: Add Intel Raptor Lake-S SoCs support")
This is not a real bug. No "Fixes" tag needed to avoid unnecessary backporting.
Signed-off-by: Ma Ke make24@iscas.ac.cn
drivers/edac/ie31200_edac.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/edac/ie31200_edac.c b/drivers/edac/ie31200_edac.c index 5a080ab65476..a5a4bb24b72a 100644 --- a/drivers/edac/ie31200_edac.c +++ b/drivers/edac/ie31200_edac.c @@ -528,6 +528,8 @@ static int ie31200_register_mci(struct pci_dev *pdev, struct res_config *cfg, in fail_unmap: iounmap(window); fail_free:
- if (mc > 0)
Since both primary and secondary memory controllers invoke device_initialize(), please remove this "if (mc > 0)" check to call put_device() unconditionally here.
edac_mc_free(mci); return ret;put_device(&priv->dev);}
Could you please address the comments above, update the commit messages, and send v2?
Thanks! -Qiuxu
[...]
--- a/drivers/edac/ie31200_edac.c +++ b/drivers/edac/ie31200_edac.c @@ -528,6 +528,8 @@ static int ie31200_register_mci(struct pci_dev *pdev, struct res_config *cfg, in fail_unmap: iounmap(window); fail_free:
- if (mc > 0)
Since both primary and secondary memory controllers invoke device_initialize(), please remove this "if (mc > 0)" check to call put_device() unconditionally here.
edac_mc_free(mci); return ret;put_device(&priv->dev);}
On the normal driver unloading path, a corresponding put_device() is also needed. Please include the following diff in your v2.
diff --git a/drivers/edac/ie31200_edac.c b/drivers/edac/ie31200_edac.c index 0aea6d59f31e..4c43d7dbe047 100644 --- a/drivers/edac/ie31200_edac.c +++ b/drivers/edac/ie31200_edac.c @@ -603,6 +603,7 @@ static void ie31200_unregister_mcis(void) mci = priv->mci; edac_mc_del_mc(mci->pdev); iounmap(priv->window); + put_device(&priv->dev); edac_mc_free(mci); } }
Thanks! -Qiuxu
linux-stable-mirror@lists.linaro.org