[PATCH 4/6] ASoC: mxs-saif: Use devm helpers to register mclk

Arina Kharlamova via B4 Relay devnull+arina.kharlamova.mbzuai.ac.ae at kernel.org
Tue Dec 1 11:23:35 PST 2026


From: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>

mxs_saif_mclk_init() registers the "mxs_saif_mclk" divider and an OF
clock provider for it, and nothing unregisters them. The divider uses
saif->base + SAIF_CTRL as its register and saif->base is mapped with
devm_platform_ioremap_resource(). When probe fails later, for example
with -EPROBE_DEFER from the DMA PCM registration, or the driver is
unbound, the clock stays registered and points into a mapping that is
gone.

On the next probe clk_register_divider() returns -EEXIST, which
mxs_saif_mclk_init() treats as success, so the clock keeps the old
register address.

Register the divider with devm_clk_hw_register_divider() and the
provider with devm_of_clk_add_hw_provider(). Both are then removed
before the register mapping when the driver is unbound or probe fails.

Fixes: 7c9e6150f2e7 ("ASoC: mxs: register saif mclk to clock framework")
---
This also covers the error path fixed by Wentao Liang's patch; only one
of the two is needed:
https://lore.kernel.org/all/20261104024048.1508618-1-vulab@iscas.ac.cn/

Signed-off-by: Arina Kharlamova <arina.kharlamova at mbzuai.ac.ae>
---
 sound/soc/mxs/mxs-saif.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/sound/soc/mxs/mxs-saif.c b/sound/soc/mxs/mxs-saif.c
index abdead349a4d..d6aaf200c9aa 100644
--- a/sound/soc/mxs/mxs-saif.c
+++ b/sound/soc/mxs/mxs-saif.c
@@ -765,24 +765,23 @@ static irqreturn_t mxs_saif_irq(int irq, void *dev_id)
 static int mxs_saif_mclk_init(struct platform_device *pdev)
 {
 	struct mxs_saif *saif = platform_get_drvdata(pdev);
-	struct device_node *np = pdev->dev.of_node;
-	struct clk *clk;
+	struct clk_hw *hw;
 	int ret;
 
-	clk = clk_register_divider(&pdev->dev, "mxs_saif_mclk",
-				   __clk_get_name(saif->clk), 0,
-				   saif->base + SAIF_CTRL,
-				   BP_SAIF_CTRL_BITCLK_MULT_RATE, 3,
-				   0, NULL);
-	if (IS_ERR(clk)) {
-		ret = PTR_ERR(clk);
+	hw = devm_clk_hw_register_divider(&pdev->dev, "mxs_saif_mclk",
+					  __clk_get_name(saif->clk), 0,
+					  saif->base + SAIF_CTRL,
+					  BP_SAIF_CTRL_BITCLK_MULT_RATE, 3,
+					  0, NULL);
+	if (IS_ERR(hw)) {
+		ret = PTR_ERR(hw);
 		if (ret == -EEXIST)
 			return 0;
 		dev_err(&pdev->dev, "failed to register mclk: %d\n", ret);
-		return PTR_ERR(clk);
+		return PTR_ERR(hw);
 	}
 
-	ret = of_clk_add_provider(np, of_clk_src_simple_get, clk);
+	ret = devm_of_clk_add_hw_provider(&pdev->dev, of_clk_hw_simple_get, hw);
 	if (ret)
 		return ret;
 

-- 
Git-157)





More information about the Linux-rockchip mailing list