Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: mediatek: Warn if clk IDs are duplicated

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>

authored by

Chen-Yu Tsai and committed by
Stephen Boyd
d54bb86b cf8a482a

+34 -6
+6
drivers/clk/mediatek/clk-cpumux.c
··· 120 120 for (i = 0; i < num; i++) { 121 121 const struct mtk_composite *mux = &clks[i]; 122 122 123 + if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) { 124 + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", 125 + node, mux->id); 126 + continue; 127 + } 128 + 123 129 clk = mtk_clk_register_cpumux(mux, regmap); 124 130 if (IS_ERR(clk)) { 125 131 pr_err("Failed to register clk %s: %pe\n", mux->name, clk);
+4 -1
drivers/clk/mediatek/clk-gate.c
··· 224 224 for (i = 0; i < num; i++) { 225 225 const struct mtk_gate *gate = &clks[i]; 226 226 227 - if (!IS_ERR_OR_NULL(clk_data->clks[gate->id])) 227 + if (!IS_ERR_OR_NULL(clk_data->clks[gate->id])) { 228 + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", 229 + node, gate->id); 228 230 continue; 231 + } 229 232 230 233 clk = mtk_clk_register_gate(gate->name, gate->parent_name, 231 234 regmap,
+14 -4
drivers/clk/mediatek/clk-mtk.c
··· 65 65 for (i = 0; i < num; i++) { 66 66 const struct mtk_fixed_clk *rc = &clks[i]; 67 67 68 - if (!IS_ERR_OR_NULL(clk_data->clks[rc->id])) 68 + if (!IS_ERR_OR_NULL(clk_data->clks[rc->id])) { 69 + pr_warn("Trying to register duplicate clock ID: %d\n", rc->id); 69 70 continue; 71 + } 70 72 71 73 clk = clk_register_fixed_rate(NULL, rc->name, rc->parent, 0, 72 74 rc->rate); ··· 130 128 for (i = 0; i < num; i++) { 131 129 const struct mtk_fixed_factor *ff = &clks[i]; 132 130 133 - if (!IS_ERR_OR_NULL(clk_data->clks[ff->id])) 131 + if (!IS_ERR_OR_NULL(clk_data->clks[ff->id])) { 132 + pr_warn("Trying to register duplicate clock ID: %d\n", ff->id); 134 133 continue; 134 + } 135 135 136 136 clk = clk_register_fixed_factor(NULL, ff->name, ff->parent_name, 137 137 CLK_SET_RATE_PARENT, ff->mult, ff->div); ··· 309 305 for (i = 0; i < num; i++) { 310 306 const struct mtk_composite *mc = &mcs[i]; 311 307 312 - if (clk_data && !IS_ERR_OR_NULL(clk_data->clks[mc->id])) 308 + if (!IS_ERR_OR_NULL(clk_data->clks[mc->id])) { 309 + pr_warn("Trying to register duplicate clock ID: %d\n", 310 + mc->id); 313 311 continue; 312 + } 314 313 315 314 clk = mtk_clk_register_composite(mc, base, lock); 316 315 ··· 375 368 for (i = 0; i < num; i++) { 376 369 const struct mtk_clk_divider *mcd = &mcds[i]; 377 370 378 - if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id])) 371 + if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id])) { 372 + pr_warn("Trying to register duplicate clock ID: %d\n", 373 + mcd->id); 379 374 continue; 375 + } 380 376 381 377 clk = clk_register_divider(NULL, mcd->name, mcd->parent_name, 382 378 mcd->flags, base + mcd->div_reg, mcd->div_shift,
+4 -1
drivers/clk/mediatek/clk-mux.c
··· 208 208 for (i = 0; i < num; i++) { 209 209 const struct mtk_mux *mux = &muxes[i]; 210 210 211 - if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) 211 + if (!IS_ERR_OR_NULL(clk_data->clks[mux->id])) { 212 + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", 213 + node, mux->id); 212 214 continue; 215 + } 213 216 214 217 clk = mtk_clk_register_mux(mux, regmap, lock); 215 218
+6
drivers/clk/mediatek/clk-pll.c
··· 394 394 for (i = 0; i < num_plls; i++) { 395 395 const struct mtk_pll_data *pll = &plls[i]; 396 396 397 + if (!IS_ERR_OR_NULL(clk_data->clks[pll->id])) { 398 + pr_warn("%pOF: Trying to register duplicate clock ID: %d\n", 399 + node, pll->id); 400 + continue; 401 + } 402 + 397 403 clk = mtk_clk_register_pll(pll, base); 398 404 399 405 if (IS_ERR(clk)) {