Skip to contentSkip to conversation

clk: fsl-sai: fix memory leak

PATCH Superseded Michael Walle 2 participants 3 messages Nov 1, 2020 – Nov 5, 2020 Common clk

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: fsl-sai: fix memory leak

If the device is removed we don't unregister the composite clock. Fix that.

Fixes 9cd10205227c ("clk: fsl-sai: new driver")
---
 drivers/clk/clk-fsl-sai.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/clk/clk-fsl-sai.c +12 -0
index 0221180a4dd7..1e81c8d8a6fd 100644
@@ -68,9 +68,20 @@ static int fsl_sai_clk_probe(struct platform_device *pdev)
 	if (IS_ERR(hw))
 		return PTR_ERR(hw);
 
+	platform_set_drvdata(pdev, hw);
+
 	return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw);
 }
 
+static int fsl_sai_clk_remove(struct platform_device *pdev)
+{
+	struct clk_hw *hw = platform_get_drvdata(pdev);
+
+	clk_hw_unregister_composite(hw);
+
+	return 0;
+}
+
 static const struct of_device_id of_fsl_sai_clk_ids[] = {
 	{ .compatible = "fsl,vf610-sai-clock" },
 	{ }
@@ -79,6 +90,7 @@ MODULE_DEVICE_TABLE(of, of_fsl_sai_clk_ids);
 
 static struct platform_driver fsl_sai_clk_driver = {
 	.probe = fsl_sai_clk_probe,
+	.remove = fsl_sai_clk_remove,
 	.driver		= {
 		.name	= "fsl-sai-clk",
 		.of_match_table = of_fsl_sai_clk_ids,
Signature · 1 line
2.20.1
maintainer
#1 lore raw

Quoting Michael Walle (2020-11-01 10:48:18)

Quoted 8 lines
drivers/clk/clk-fsl-sai.c +0 -0
index 0221180a4dd7..1e81c8d8a6fd 100644
@@ -68,9 +68,20 @@ static int fsl_sai_clk_probe(struct platform_device *pdev)
        if (IS_ERR(hw))
                return PTR_ERR(hw);
 

drivers/clk/clk-fsl-sai.c static int fsl_sai_clk_probe(struct platform_device *pdev) · line 80

Quoted 10 lines
drivers/clk/clk-fsl-sai.c +7 -0
+       platform_set_drvdata(pdev, hw);
+
        return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, hw);
 }
 
+static int fsl_sai_clk_remove(struct platform_device *pdev)
+{
+       struct clk_hw *hw = platform_get_drvdata(pdev);
+
+       clk_hw_unregister_composite(hw);

Should we add a devm_clk_hw_register_composite() API and use it here? That way we don't need a remove function and devm can be used throughout.

Quoted 7 lines
drivers/clk/clk-fsl-sai.c +4 -0
+
+       return 0;
+}
+
 static const struct of_device_id of_fsl_sai_clk_ids[] = {
        { .compatible = "fsl,vf610-sai-clock" },
        { }
#2 lore raw

Am 2020-11-05 01:29, schrieb Stephen Boyd:

Quoted 16 lines

Quoting Michael Walle (2020-11-01 10:48:18)

Quoted 15 lines
drivers/clk/clk-fsl-sai.c +2 -0
index 0221180a4dd7..1e81c8d8a6fd 100644
@@ -68,9 +68,20 @@ static int fsl_sai_clk_probe(struct platform_device 
 *pdev)
        if (IS_ERR(hw))
                return PTR_ERR(hw);
 
+       platform_set_drvdata(pdev, hw);
+
        return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, 
 hw);
 }
 
Quoted 9 lines

drivers/clk/clk-fsl-sai.c static int fsl_sai_clk_probe(struct platform_device *pdev) · line 80

Quoted 5 lines
drivers/clk/clk-fsl-sai.c +5 -0
+static int fsl_sai_clk_remove(struct platform_device *pdev)
+{
+       struct clk_hw *hw = platform_get_drvdata(pdev);
+
+       clk_hw_unregister_composite(hw);

Should we add a devm_clk_hw_register_composite() API and use it here? That way we don't need a remove function and devm can be used throughout.

Can do. But does adding a devm_ function qualify for the -stable branch? Or should I expect to have exactly this patch as a backport there then?

-michael