Skip to contentSkip to conversation

clk: mediatek: Unregister apmixedsys clocks on unbind

PATCH In review Guangshuo Li 3 participants 7 messages Nov 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover clk: mediatek: Unregister apmixedsys clocks on unbind

Pair apmixedsys clock registration with removal on four MediaTek SoCs.

Guangshuo Li (4):
clk: mediatek: mt8167: Unregister apmixedsys clocks on unbind
clk: mediatek: mt8183: Unregister apmixedsys clocks on unbind
clk: mediatek: mt8365: Unregister apmixedsys clocks on unbind
clk: mediatek: mt8516: Unregister apmixedsys clocks on unbind

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5

#1 lore raw

PATCH 1/4 clk: mediatek: mt8167: Unregister apmixedsys clocks on unbind

The apmixedsys driver leaves the OF provider and clocks registered on unbind. The clock table is device-managed, so the provider can retain a pointer to released storage.

Remove the provider and unregister the dividers and PLLs during removal.

This issue was found by our static analysis tool under development.

Fixes b27284336aa4 ("clk: mediatek: mt8167: Move apmixedsys as platform_driver in new file")
---
 drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/clk/mediatek/clk-mt8167-apmixedsys.c +12 -0
index fb6c21bbeef8..70fc5e5215e5 100644
@@ -118,6 +118,8 @@ static int clk_mt8167_apmixed_probe(struct platform_device *pdev)
 	if (ret)
 		goto unregister_dividers;
 
+	platform_set_drvdata(pdev, clk_data);
+
 	return 0;
 
 unregister_dividers:
@@ -128,6 +130,15 @@ static int clk_mt8167_apmixed_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static void clk_mt8167_apmixed_remove(struct platform_device *pdev)
+{
+	struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
+
+	of_clk_del_provider(pdev->dev.of_node);
+	mtk_clk_unregister_dividers(adj_divs, ARRAY_SIZE(adj_divs), clk_data);
+	mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
+}
+
 static const struct of_device_id of_match_clk_mt8167_apmixed[] = {
 	{ .compatible = "mediatek,mt8167-apmixedsys" },
 	{ /* sentinel */ }
@@ -136,6 +147,7 @@ MODULE_DEVICE_TABLE(of, of_match_clk_mt8167_apmixed);
 
 static struct platform_driver clk_mt8167_apmixed_drv = {
 	.probe = clk_mt8167_apmixed_probe,
+	.remove = clk_mt8167_apmixed_remove,
 	.driver = {
 		.name = "clk-mt8167-apmixed",
 		.of_match_table = of_match_clk_mt8167_apmixed,
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/4 clk: mediatek: mt8183: Unregister apmixedsys clocks on unbind

In reply to Guangshuo Li

The apmixedsys driver leaves the OF provider and clocks registered on unbind. The clock table is device-managed, so the provider can retain a pointer to released storage.

Remove the provider and unregister the gates and PLLs during removal.

This issue was found by our static analysis tool under development.

Fixes acddfc2c261b ("clk: mediatek: Add MT8183 clock support")
---
 drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/clk/mediatek/clk-mt8183-apmixedsys.c +13 -0
index 6242d4f5376e..e1fc3f2beafa 100644
@@ -168,6 +168,8 @@ static int clk_mt8183_apmixed_probe(struct platform_device *pdev)
 	if (ret)
 		goto unregister_gates;
 
+	platform_set_drvdata(pdev, clk_data);
+
 	return 0;
 
 unregister_gates:
@@ -178,6 +180,16 @@ static int clk_mt8183_apmixed_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static void clk_mt8183_apmixed_remove(struct platform_device *pdev)
+{
+	struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
+
+	of_clk_del_provider(pdev->dev.of_node);
+	mtk_clk_unregister_gates(apmixed_clks, ARRAY_SIZE(apmixed_clks),
+				 clk_data);
+	mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
+}
+
 static const struct of_device_id of_match_clk_mt8183_apmixed[] = {
 	{ .compatible = "mediatek,mt8183-apmixedsys" },
 	{ /* sentinel */ }
@@ -186,6 +198,7 @@ MODULE_DEVICE_TABLE(of, of_match_clk_mt8183_apmixed);
 
 static struct platform_driver clk_mt8183_apmixed_drv = {
 	.probe = clk_mt8183_apmixed_probe,
+	.remove = clk_mt8183_apmixed_remove,
 	.driver = {
 		.name = "clk-mt8183-apmixed",
 		.of_match_table = of_match_clk_mt8183_apmixed,
Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/4 clk: mediatek: mt8365: Unregister apmixedsys clocks on unbind

In reply to Guangshuo Li

The apmixedsys driver leaves the OF provider and clocks registered on unbind. The clock table is device-managed, so the provider can retain a pointer to released storage.

Remove the provider and unregister the PLLs during removal.

This issue was found by our static analysis tool under development.

Fixes d46adccb7966 ("clk: mediatek: add driver for MT8365 SoC")
---
 drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/clk/mediatek/clk-mt8365-apmixedsys.c +11 -0
index e331aa28a4bd..386b0c66bf4f 100644
@@ -141,6 +141,8 @@ static int clk_mt8365_apmixed_probe(struct platform_device *pdev)
 	if (ret)
 		goto unregister_plls;
 
+	platform_set_drvdata(pdev, clk_data);
+
 	return 0;
 
 unregister_plls:
@@ -149,6 +151,14 @@ static int clk_mt8365_apmixed_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static void clk_mt8365_apmixed_remove(struct platform_device *pdev)
+{
+	struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
+
+	of_clk_del_provider(pdev->dev.of_node);
+	mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
+}
+
 static const struct of_device_id of_match_clk_mt8365_apmixed[] = {
 	{ .compatible = "mediatek,mt8365-apmixedsys" },
 	{ /* sentinel */ }
@@ -157,6 +167,7 @@ MODULE_DEVICE_TABLE(of, of_match_clk_mt8365_apmixed);
 
 static struct platform_driver clk_mt8365_apmixed_drv = {
 	.probe = clk_mt8365_apmixed_probe,
+	.remove = clk_mt8365_apmixed_remove,
 	.driver = {
 		.name = "clk-mt8365-apmixed",
 		.of_match_table = of_match_clk_mt8365_apmixed,
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/4 clk: mediatek: mt8516: Unregister apmixedsys clocks on unbind

In reply to Guangshuo Li

The apmixedsys driver leaves the OF provider and clocks registered on unbind. The clock table is device-managed, so the provider can retain a pointer to released storage.

Remove the provider and unregister the PLLs during removal.

This issue was found by our static analysis tool under development.

Fixes f419069ad864 ("clk: mediatek: mt8516: Move apmixedsys clock driver to its own file")
---
 drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/clk/mediatek/clk-mt8516-apmixedsys.c +11 -0
index 2a6206cae2f0..abb2a626628c 100644
@@ -95,6 +95,8 @@ static int clk_mt8516_apmixed_probe(struct platform_device *pdev)
 	if (ret)
 		goto unregister_plls;
 
+	platform_set_drvdata(pdev, clk_data);
+
 	return 0;
 
 unregister_plls:
@@ -103,6 +105,14 @@ static int clk_mt8516_apmixed_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static void clk_mt8516_apmixed_remove(struct platform_device *pdev)
+{
+	struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
+
+	of_clk_del_provider(pdev->dev.of_node);
+	mtk_clk_unregister_plls(plls, ARRAY_SIZE(plls), clk_data);
+}
+
 static const struct of_device_id of_match_clk_mt8516_apmixed[] = {
 	{ .compatible = "mediatek,mt8516-apmixedsys" },
 	{ /* sentinel */ }
@@ -111,6 +121,7 @@ MODULE_DEVICE_TABLE(of, of_match_clk_mt8516_apmixed);
 
 static struct platform_driver clk_mt8516_apmixed_drv = {
 	.probe = clk_mt8516_apmixed_probe,
+	.remove = clk_mt8516_apmixed_remove,
 	.driver = {
 		.name = "clk-mt8516-apmixed",
 		.of_match_table = of_match_clk_mt8516_apmixed,
Signature · 1 line
2.43.0
#5 lore raw
In reply to Guangshuo Li
Quoted 2 lines · Guangshuo Li

Pair apmixedsys clock registration with removal on four MediaTek SoCs.

You are checking the wrong tree.

This series is mostly obsoleted by the following commits:

c9c2fd1a53a4 clk: mediatek: mt8516-apmixedsys: Switch to common probe/remove helpers
68d1fa487766 clk: mediatek: mt8183: Switch to common probe/remove helpers 9421b0b085c0 clk: mediatek: mt8167-apmixedsys: Switch to common probe/remove helpers

Quoted 4 lines

Guangshuo Li (4):
clk: mediatek: mt8167: Unregister apmixedsys clocks on unbind
clk: mediatek: mt8183: Unregister apmixedsys clocks on unbind
clk: mediatek: mt8365: Unregister apmixedsys clocks on unbind

This is the only one that applies. But we probably want to convert it to the common helpers as well.

ChenYu

Quoted 4 lines

clk: mediatek: mt8516: Unregister apmixedsys clocks on unbind

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5

#6 lore raw
In reply to Guangshuo Li

Hi Guangshuo,

Quoted 10 lines · Guangshuo Li

Pair apmixedsys clock registration with removal on four MediaTek SoCs.

Guangshuo Li (4):
clk: mediatek: mt8167: Unregister apmixedsys clocks on unbind
clk: mediatek: mt8183: Unregister apmixedsys clocks on unbind
clk: mediatek: mt8365: Unregister apmixedsys clocks on unbind
clk: mediatek: mt8516: Unregister apmixedsys clocks on unbind

base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5

As ChenYu mentioned, my previous series fixed these issues. However, due to my insufficient verification,
some regressions were introduced, so I'm preparing a followup series. During the correction process, sadly I found and fixing several bugs in MediaTek CCF, so please wait a few more days...

Best regards,
Akari