lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220519134728.456643-6-y.oudjana@protonmail.com>
Date:   Thu, 19 May 2022 17:47:27 +0400
From:   Yassine Oudjana <yassine.oudjana@...il.com>
To:     Michael Turquette <mturquette@...libre.com>,
        Stephen Boyd <sboyd@...nel.org>,
        Matthias Brugger <matthias.bgg@...il.com>,
        Philipp Zabel <p.zabel@...gutronix.de>
Cc:     Yassine Oudjana <y.oudjana@...tonmail.com>,
        Chen-Yu Tsai <wenst@...omium.org>,
        Miles Chen <miles.chen@...iatek.com>,
        AngeloGioacchino Del Regno 
        <angelogioacchino.delregno@...labora.com>,
        Chun-Jie Chen <chun-jie.chen@...iatek.com>,
        José Expósito <jose.exposito89@...il.com>,
        Rex-BC Chen <rex-bc.chen@...iatek.com>,
        Yassine Oudjana <yassine.oudjana@...il.com>,
        linux-mediatek@...ts.infradead.org, linux-clk@...r.kernel.org,
        linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
        ~postmarketos/upstreaming@...ts.sr.ht
Subject: [PATCH 5/6] clk: mediatek: Unregister reset controller on simple remove

From: Yassine Oudjana <y.oudjana@...tonmail.com>

Store clk_data and rst_data pointers in a new wrapper struct,
set it as platform driver data, then use it in mtk_clk_simple_remove
to unregister the reset controller.

Signed-off-by: Yassine Oudjana <y.oudjana@...tonmail.com>
---
Dependencies:
- clk: mediatek: Move to struct clk_hw provider APIs (series)
  https://patchwork.kernel.org/project/linux-mediatek/cover/20220510104804.544597-1-wenst@chromium.org/ 
- Cleanup MediaTek clk reset drivers and support MT8192/MT8195 (series)
  https://patchwork.kernel.org/project/linux-mediatek/cover/20220503093856.22250-1-rex-bc.chen@mediatek.com/
- Export required symbols to compile clk drivers as module (single patch)
  https://patchwork.kernel.org/project/linux-mediatek/patch/20220518111652.223727-7-angelogioacchino.delregno@collabora.com/

 drivers/clk/mediatek/clk-mtk.c | 47 +++++++++++++++++++++-------------
 drivers/clk/mediatek/clk-mtk.h |  5 ++++
 2 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 1b5591733e2b..3382802663f4 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -422,35 +422,41 @@ void mtk_clk_unregister_dividers(const struct mtk_clk_divider *mcds, int num,
 int mtk_clk_simple_probe(struct platform_device *pdev)
 {
 	const struct mtk_clk_desc *mcd;
-	struct clk_hw_onecell_data *clk_data;
+	struct mtk_simple_clk_controller *clk_ctrl;
 	struct device_node *node = pdev->dev.of_node;
-	struct mtk_clk_rst_data *rst_data;
 	int r;
 
 	mcd = of_device_get_match_data(&pdev->dev);
 	if (!mcd)
 		return -EINVAL;
 
-	clk_data = mtk_alloc_clk_data(mcd->num_clks);
-	if (!clk_data)
+	clk_ctrl = kzalloc(sizeof(*clk_ctrl), GFP_KERNEL);
+	if (!clk_ctrl)
 		return -ENOMEM;
 
+	clk_ctrl->clk_data = mtk_alloc_clk_data(mcd->num_clks);
+	if (!clk_ctrl->clk_data) {
+		r = -ENOMEM;
+		goto free_clk_ctrl;
+	}
+
 	r = mtk_clk_register_gates_with_dev(node, mcd->clks, mcd->num_clks,
-					    clk_data, &pdev->dev);
+					    clk_ctrl->clk_data, &pdev->dev);
 	if (r)
-		goto free_data;
+		goto free_clk_data;
 
-	r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
+	r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_ctrl->clk_data);
 	if (r)
 		goto unregister_clks;
 
-	platform_set_drvdata(pdev, clk_data);
+	platform_set_drvdata(pdev, clk_ctrl);
 
 	if (mcd->rst_desc) {
-		rst_data = mtk_register_reset_controller_with_dev(&pdev->dev,
-							   	  mcd->rst_desc);
-		if (IS_ERR(rst_data)) {
-			r = PTR_ERR(rst_data);
+		clk_ctrl->rst_data =
+			mtk_register_reset_controller_with_dev(&pdev->dev,
+							       mcd->rst_desc);
+		if (IS_ERR(clk_ctrl->rst_data)) {
+			r = PTR_ERR(clk_ctrl->rst_data);
 			goto unregister_clks;
 		}
 	}
@@ -458,9 +464,11 @@ int mtk_clk_simple_probe(struct platform_device *pdev)
 	return r;
 
 unregister_clks:
-	mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data);
-free_data:
-	mtk_free_clk_data(clk_data);
+	mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_ctrl->clk_data);
+free_clk_data:
+	mtk_free_clk_data(clk_ctrl->clk_data);
+free_clk_ctrl:
+	kfree(clk_ctrl);
 	return r;
 }
 EXPORT_SYMBOL_GPL(mtk_clk_simple_probe);
@@ -468,12 +476,15 @@ EXPORT_SYMBOL_GPL(mtk_clk_simple_probe);
 int mtk_clk_simple_remove(struct platform_device *pdev)
 {
 	const struct mtk_clk_desc *mcd = of_device_get_match_data(&pdev->dev);
-	struct clk_hw_onecell_data *clk_data = platform_get_drvdata(pdev);
+	struct mtk_simple_clk_controller *clk_ctrl = platform_get_drvdata(pdev);
 	struct device_node *node = pdev->dev.of_node;
 
 	of_clk_del_provider(node);
-	mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_data);
-	mtk_free_clk_data(clk_data);
+	if (clk_ctrl->rst_data)
+		mtk_unregister_reset_controller(clk_ctrl->rst_data);
+	mtk_clk_unregister_gates(mcd->clks, mcd->num_clks, clk_ctrl->clk_data);
+	mtk_free_clk_data(clk_ctrl->clk_data);
+	kfree(clk_ctrl);
 
 	return 0;
 }
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index 1b95c484d5aa..fa092bca97c8 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -189,6 +189,11 @@ void mtk_free_clk_data(struct clk_hw_onecell_data *clk_data);
 struct clk_hw *mtk_clk_register_ref2usb_tx(const char *name,
 			const char *parent_name, void __iomem *reg);
 
+struct mtk_simple_clk_controller {
+	struct clk_hw_onecell_data *clk_data;
+	struct mtk_clk_rst_data *rst_data;
+};
+
 struct mtk_clk_desc {
 	const struct mtk_gate *clks;
 	size_t num_clks;
-- 
2.36.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ