clk: mediatek: Warn if clk IDs are duplicated
authorChen-Yu Tsai <wenst@chromium.org>
Tue, 8 Feb 2022 12:40:34 +0000 (20:40 +0800)
committerStephen Boyd <sboyd@kernel.org>
Thu, 17 Feb 2022 20:12:25 +0000 (12:12 -0800)
The Mediatek clk driver library handles duplicate clock IDs in two
different ways: either ignoring the duplicate entry, or overwriting
the old clk. Either way may cause unexpected behavior, and the latter
also causes an orphan clk that cannot be cleaned up.

Align the behavior so that later duplicate entries are ignored, and
a warning printed. The warning will also aid in making the issue
noticeable.

Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: Miles Chen <miles.chen@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Link: https://lore.kernel.org/r/20220208124034.414635-32-wenst@chromium.org
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/mediatek/clk-cpumux.c
drivers/clk/mediatek/clk-gate.c
drivers/clk/mediatek/clk-mtk.c
drivers/clk/mediatek/clk-mux.c
drivers/clk/mediatek/clk-pll.c

index 499c604322807c6e34e7465a2472c8e9cf61a398..c11b3fae622e40b54d52fc493ccbc38e3baf3654 100644 (file)
@@ -120,6 +120,12 @@ int mtk_clk_register_cpumuxes(struct device_node *node,
        for (i = 0; i < num; i++) {
                const struct mtk_composite *mux = &clks[i];
 
+               if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) {
+                       pr_warn("%pOF: Trying to register duplicate clock ID: %d\n",
+                               node, mux->id);
+                       continue;
+               }
+
                clk = mtk_clk_register_cpumux(mux, regmap);
                if (IS_ERR(clk)) {
                        pr_err("Failed to register clk %s: %pe\n", mux->name, clk);
index 631ff170b7b9a5fc9731ee9a945330e8ddba7471..da52023f845588b1a9a4b252664a616498dfde1e 100644 (file)
@@ -224,8 +224,11 @@ int mtk_clk_register_gates_with_dev(struct device_node *node,
        for (i = 0; i < num; i++) {
                const struct mtk_gate *gate = &clks[i];
 
-               if (!IS_ERR_OR_NULL(clk_data->clks[gate->id]))
+               if (!IS_ERR_OR_NULL(clk_data->clks[gate->id])) {
+                       pr_warn("%pOF: Trying to register duplicate clock ID: %d\n",
+                               node, gate->id);
                        continue;
+               }
 
                clk = mtk_clk_register_gate(gate->name, gate->parent_name,
                                            regmap,
index 0e027be0d5fc998c8f76cfffefec326a64704059..b4063261cf56104f8ab504dca431112a02ba6985 100644 (file)
@@ -65,8 +65,10 @@ int mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num,
        for (i = 0; i < num; i++) {
                const struct mtk_fixed_clk *rc = &clks[i];
 
-               if (!IS_ERR_OR_NULL(clk_data->clks[rc->id]))
+               if (!IS_ERR_OR_NULL(clk_data->clks[rc->id])) {
+                       pr_warn("Trying to register duplicate clock ID: %d\n", rc->id);
                        continue;
+               }
 
                clk = clk_register_fixed_rate(NULL, rc->name, rc->parent, 0,
                                              rc->rate);
@@ -128,8 +130,10 @@ int mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num,
        for (i = 0; i < num; i++) {
                const struct mtk_fixed_factor *ff = &clks[i];
 
-               if (!IS_ERR_OR_NULL(clk_data->clks[ff->id]))
+               if (!IS_ERR_OR_NULL(clk_data->clks[ff->id])) {
+                       pr_warn("Trying to register duplicate clock ID: %d\n", ff->id);
                        continue;
+               }
 
                clk = clk_register_fixed_factor(NULL, ff->name, ff->parent_name,
                                CLK_SET_RATE_PARENT, ff->mult, ff->div);
@@ -305,8 +309,11 @@ int mtk_clk_register_composites(const struct mtk_composite *mcs, int num,
        for (i = 0; i < num; i++) {
                const struct mtk_composite *mc = &mcs[i];
 
-               if (clk_data && !IS_ERR_OR_NULL(clk_data->clks[mc->id]))
+               if (!IS_ERR_OR_NULL(clk_data->clks[mc->id])) {
+                       pr_warn("Trying to register duplicate clock ID: %d\n",
+                               mc->id);
                        continue;
+               }
 
                clk = mtk_clk_register_composite(mc, base, lock);
 
@@ -368,8 +375,11 @@ int mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num,
        for (i = 0; i <  num; i++) {
                const struct mtk_clk_divider *mcd = &mcds[i];
 
-               if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id]))
+               if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id])) {
+                       pr_warn("Trying to register duplicate clock ID: %d\n",
+                               mcd->id);
                        continue;
+               }
 
                clk = clk_register_divider(NULL, mcd->name, mcd->parent_name,
                        mcd->flags, base +  mcd->div_reg, mcd->div_shift,
index f51e67650f03a6a55ff1449d2c877d1d7d9579ef..21ad5a4afd65c537453101ee671271bbd4ff0339 100644 (file)
@@ -208,8 +208,11 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes,
        for (i = 0; i < num; i++) {
                const struct mtk_mux *mux = &muxes[i];
 
-               if (!IS_ERR_OR_NULL(clk_data->clks[mux->id]))
+               if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) {
+                       pr_warn("%pOF: Trying to register duplicate clock ID: %d\n",
+                               node, mux->id);
                        continue;
+               }
 
                clk = mtk_clk_register_mux(mux, regmap, lock);
 
index 817a80293bfc25ae84cb4d8a5bbb962d629dcdaa..ccaa2085ab4db1f069660c702ca89a245cad7633 100644 (file)
@@ -394,6 +394,12 @@ int mtk_clk_register_plls(struct device_node *node,
        for (i = 0; i < num_plls; i++) {
                const struct mtk_pll_data *pll = &plls[i];
 
+               if (!IS_ERR_OR_NULL(clk_data->clks[pll->id])) {
+                       pr_warn("%pOF: Trying to register duplicate clock ID: %d\n",
+                               node, pll->id);
+                       continue;
+               }
+
                clk = mtk_clk_register_pll(pll, base);
 
                if (IS_ERR(clk)) {