[PATCH v3] net: wan: framer: pef2256: Switch to devm_mfd_add_devices()

Haotian Zhang posted 1 patch 1 month, 2 weeks ago
drivers/net/wan/framer/pef2256/pef2256.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH v3] net: wan: framer: pef2256: Switch to devm_mfd_add_devices()
Posted by Haotian Zhang 1 month, 2 weeks ago
The driver calls mfd_add_devices() but fails to call mfd_remove_devices()
in error paths after successful MFD device registration and in the remove
function. This leads to resource leaks where MFD child devices are not
properly unregistered.

Replace mfd_add_devices with devm_mfd_add_devices to automatically
manage the device resources.

Fixes: c96e976d9a05 ("net: wan: framer: Add support for the Lantiq PEF2256 framer")
Suggested-by: Herve Codina <herve.codina@bootlin.com>
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
---
Changes in v3:
  - Also replace mfd_add_devices() with devm_mfd_add_devices()
    in pef2256_add_audio_devices(), which was overlooked by
    previous patch.
Changes in v2:
  - Use devm_mfd_add_devices() instead of manual cleanup.
---
---
 drivers/net/wan/framer/pef2256/pef2256.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wan/framer/pef2256/pef2256.c b/drivers/net/wan/framer/pef2256/pef2256.c
index 1e4c8e85d598..180edde177c6 100644
--- a/drivers/net/wan/framer/pef2256/pef2256.c
+++ b/drivers/net/wan/framer/pef2256/pef2256.c
@@ -637,7 +637,7 @@ static int pef2256_add_audio_devices(struct pef2256 *pef2256)
 		audio_devs[i].id = i;
 	}
 
-	ret = mfd_add_devices(pef2256->dev, 0, audio_devs, count, NULL, 0, NULL);
+	ret = devm_mfd_add_devices(pef2256->dev, 0, audio_devs, count, NULL, 0, NULL);
 	kfree(audio_devs);
 	return ret;
 }
@@ -812,8 +812,8 @@ static int pef2256_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, pef2256);
 
-	ret = mfd_add_devices(pef2256->dev, 0, pef2256_devs,
-			      ARRAY_SIZE(pef2256_devs), NULL, 0, NULL);
+	ret = devm_mfd_add_devices(pef2256->dev, 0, pef2256_devs,
+				   ARRAY_SIZE(pef2256_devs), NULL, 0, NULL);
 	if (ret) {
 		dev_err(pef2256->dev, "add devices failed (%d)\n", ret);
 		return ret;
-- 
2.50.1.windows.1
Re: [PATCH v3] net: wan: framer: pef2256: Switch to devm_mfd_add_devices()
Posted by Herve Codina 1 month, 2 weeks ago
Hi Haotian,

On Wed,  5 Nov 2025 11:47:16 +0800
Haotian Zhang <vulab@iscas.ac.cn> wrote:

> The driver calls mfd_add_devices() but fails to call mfd_remove_devices()
> in error paths after successful MFD device registration and in the remove
> function. This leads to resource leaks where MFD child devices are not
> properly unregistered.
> 
> Replace mfd_add_devices with devm_mfd_add_devices to automatically
> manage the device resources.
> 
> Fixes: c96e976d9a05 ("net: wan: framer: Add support for the Lantiq PEF2256 framer")
> Suggested-by: Herve Codina <herve.codina@bootlin.com>
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>

Not sure that 'Suggested-by: Jakub Kicinski' was needed according to his
comments on v2. Also, you forgot my 'Acked-by' I sent on v2.

Anyway, the v3 is ok on my side

Acked-by: Herve Codina <herve.codina@bootlin.com>

Best regards,
Hervé