EDAC/ie31200: Fix error handling in ie31200_register_mci
Subsystems (2)
PATCH v3 1/1 EDAC/ie31200: Fix error handling in ie31200_register_mci
ie31200_register_mci() calls device_initialize() for priv->dev unconditionally. However, in the error path, put_device() is not called, leading to an imbalance. Similarly, in the unload path, put_device() is missing.
Although edac_mc_free() eventually frees the memory, it does not release the device initialized by device_initialize(). For code readability and proper pairing of device_initialize()/put_device(), add put_device() calls in both error and unload paths.
Found by code review.
---
Changes in v3:
- moved put_device() from fail_free to fail_unmap to avoid using uninitialized priv variable when window allocation fails. Changes in v2:
- modified the patch, thanks for developer's suggestions;
- removed Fixes line.
--- drivers/edac/ie31200_edac.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/edac/ie31200_edac.c +2 -0
@@ -526,6 +526,7 @@ static int ie31200_register_mci(struct pci_dev *pdev, struct res_config *cfg, in ie31200_pvt.priv[mc] = priv;return 0 ; fail_unmap: +put_device (&priv->dev);iounmap (window); fail_free:edac_mc_free (mci);
@@ -598,6 +599,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); } }
Signature · 1 line
2.17.1
Borislav Petkov
maintainerQuoted 10 lines · Ma Ke
ie31200_register_mci()callsdevice_initialize()forpriv->devunconditionally. However, in the error path,put_device()is not called, leading to an imbalance. Similarly, in the unload path,put_device()is missing.Although
edac_mc_free()eventually frees the memory, it does not release the device initialized bydevice_initialize(). For code readability and proper pairing of device_initialize()/put_device(), addput_device()calls in both error and unload paths.
Quoted 6 lines
Found by code review.
Signed-off-by Ma Ke <[email protected]>---
Changes in v3:
- movedput_device()fromfail_freetofail_unmapto avoid using uninitialized priv variable when window allocation fails.
Zapped v2 from the tree for the time being.
Quoted 3 lines
Changes in v2:
- modified the patch, thanks for developer's suggestions;
- removed Fixes line.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteQuoted 18 lines
From: Ma Ke <[email protected]>
Sent: Thursday, November 6, 2025 4:48 PM
To: [email protected]; [email protected]; Luck, Tony <[email protected]>; Zhuo, Qiuxu <[email protected]>
Cc: [email protected]; [email protected]; akpm@linux- foundation.org; Ma Ke <[email protected]>
Subject: [PATCH v3] EDAC/ie31200: Fix error handling inie31200_register_mci
ie31200_register_mci()callsdevice_initialize()forpriv->devunconditionally. However, in the error path,put_device()is not called, leading to an imbalance. Similarly, in the unload path,put_device()is missing.Although
edac_mc_free()eventually frees the memory, it does not release the device initialized bydevice_initialize(). For code readability and proper pairing of device_initialize()/put_device(), addput_device()calls in both error and unload paths.
Quoted 7 lines
Found by code review.
Signed-off-by Ma Ke <[email protected]>---
Changes in v3:
- movedput_device()fromfail_freetofail_unmapto avoid using uninitialized priv variable when window allocation fails.
Oops ... I didn't catch that during v2 review.
For v3:
Quoted 1 line
[...]
Luck, Tony
maintainerQuoted 5 lines · Ma Ke
ie31200_register_mci()callsdevice_initialize()forpriv->devunconditionally. However, in the error path,put_device()is not called, leading to an imbalance. Similarly, in the unload path,put_device()is missing.
Quoted 8 lines
Although
edac_mc_free()eventually frees the memory, it does not release the device initialized bydevice_initialize(). For code readability and proper pairing of device_initialize()/put_device(), addput_device()calls in both error and unload paths.Found by code review.
Signed-off-by Ma Ke <[email protected]>
Applied v3 version.
Thanks
-Tony