[PATCH] soc: imx8m: unregister the soc and cpufreq devices if action setup fails

Wentao Liang vulab at iscas.ac.cn
Tue Nov 3 18:14:32 PST 2026


imx8m_soc_probe() registers the soc device and the imx-cpufreq-dt
platform device and then installs a devm action to unregister each of
them.  With plain devm_add_action() a failure to install the action
returns the error without unregistering the device that was just
registered, so the device is leaked and its sysfs name stays occupied.

Use devm_add_action_or_reset(), which runs the unregister callback when
the action cannot be added.

Fixes: cf7139aac463 ("soc: imx8m: Unregister cpufreq and soc dev in cleanup path")
Cc: stable at vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab at iscas.ac.cn>
---
 drivers/soc/imx/soc-imx8m.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/soc/imx/soc-imx8m.c b/drivers/soc/imx/soc-imx8m.c
index 70b281927c4b..ffca59c3b6c8 100644
--- a/drivers/soc/imx/soc-imx8m.c
+++ b/drivers/soc/imx/soc-imx8m.c
@@ -290,7 +290,7 @@ static int imx8m_soc_probe(struct platform_device *pdev)
 	if (IS_ERR(soc_dev))
 		return PTR_ERR(soc_dev);
 
-	ret = devm_add_action(dev, imx8m_unregister_soc, soc_dev);
+	ret = devm_add_action_or_reset(dev, imx8m_unregister_soc, soc_dev);
 	if (ret)
 		return ret;
 
@@ -302,7 +302,7 @@ static int imx8m_soc_probe(struct platform_device *pdev)
 		if (IS_ERR(cpufreq_dev))
 			return dev_err_probe(dev, PTR_ERR(cpufreq_dev),
 					     "Failed to register imx-cpufreq-dev device\n");
-		ret = devm_add_action(dev, imx8m_unregister_cpufreq, cpufreq_dev);
+		ret = devm_add_action_or_reset(dev, imx8m_unregister_cpufreq, cpufreq_dev);
 		if (ret)
 			return ret;
 	}
-- 
2.34.1




More information about the linux-arm-kernel mailing list