Skip to content

Commit d54bb86

Browse files
wensbebarino
authored andcommitted
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>
1 parent cf8a482 commit d54bb86

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

drivers/clk/mediatek/clk-cpumux.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ int mtk_clk_register_cpumuxes(struct device_node *node,
120120
for (i = 0; i < num; i++) {
121121
const struct mtk_composite *mux = &clks[i];
122122

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+
123129
clk = mtk_clk_register_cpumux(mux, regmap);
124130
if (IS_ERR(clk)) {
125131
pr_err("Failed to register clk %s: %pe\n", mux->name, clk);

drivers/clk/mediatek/clk-gate.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ int mtk_clk_register_gates_with_dev(struct device_node *node,
224224
for (i = 0; i < num; i++) {
225225
const struct mtk_gate *gate = &clks[i];
226226

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);
228230
continue;
231+
}
229232

230233
clk = mtk_clk_register_gate(gate->name, gate->parent_name,
231234
regmap,

drivers/clk/mediatek/clk-mtk.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ int mtk_clk_register_fixed_clks(const struct mtk_fixed_clk *clks, int num,
6565
for (i = 0; i < num; i++) {
6666
const struct mtk_fixed_clk *rc = &clks[i];
6767

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);
6970
continue;
71+
}
7072

7173
clk = clk_register_fixed_rate(NULL, rc->name, rc->parent, 0,
7274
rc->rate);
@@ -128,8 +130,10 @@ int mtk_clk_register_factors(const struct mtk_fixed_factor *clks, int num,
128130
for (i = 0; i < num; i++) {
129131
const struct mtk_fixed_factor *ff = &clks[i];
130132

131-
if (!IS_ERR_OR_NULL(clk_data->clks[ff->id]))
133+
if (!IS_ERR_OR_NULL(clk_data->clks[ff->id])) {
134+
pr_warn("Trying to register duplicate clock ID: %d\n", ff->id);
132135
continue;
136+
}
133137

134138
clk = clk_register_fixed_factor(NULL, ff->name, ff->parent_name,
135139
CLK_SET_RATE_PARENT, ff->mult, ff->div);
@@ -305,8 +309,11 @@ int mtk_clk_register_composites(const struct mtk_composite *mcs, int num,
305309
for (i = 0; i < num; i++) {
306310
const struct mtk_composite *mc = &mcs[i];
307311

308-
if (clk_data && !IS_ERR_OR_NULL(clk_data->clks[mc->id]))
312+
if (!IS_ERR_OR_NULL(clk_data->clks[mc->id])) {
313+
pr_warn("Trying to register duplicate clock ID: %d\n",
314+
mc->id);
309315
continue;
316+
}
310317

311318
clk = mtk_clk_register_composite(mc, base, lock);
312319

@@ -368,8 +375,11 @@ int mtk_clk_register_dividers(const struct mtk_clk_divider *mcds, int num,
368375
for (i = 0; i < num; i++) {
369376
const struct mtk_clk_divider *mcd = &mcds[i];
370377

371-
if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id]))
378+
if (!IS_ERR_OR_NULL(clk_data->clks[mcd->id])) {
379+
pr_warn("Trying to register duplicate clock ID: %d\n",
380+
mcd->id);
372381
continue;
382+
}
373383

374384
clk = clk_register_divider(NULL, mcd->name, mcd->parent_name,
375385
mcd->flags, base + mcd->div_reg, mcd->div_shift,

drivers/clk/mediatek/clk-mux.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,11 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes,
208208
for (i = 0; i < num; i++) {
209209
const struct mtk_mux *mux = &muxes[i];
210210

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);
212214
continue;
215+
}
213216

214217
clk = mtk_clk_register_mux(mux, regmap, lock);
215218

drivers/clk/mediatek/clk-pll.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,12 @@ int mtk_clk_register_plls(struct device_node *node,
394394
for (i = 0; i < num_plls; i++) {
395395
const struct mtk_pll_data *pll = &plls[i];
396396

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+
397403
clk = mtk_clk_register_pll(pll, base);
398404

399405
if (IS_ERR(clk)) {

0 commit comments

Comments
 (0)