Skip to content

Commit 4e94ea5

Browse files
wensbebarino
authored andcommitted
clk: mediatek: cpumux: Implement error handling in register API
The cpumux clk type registration function does not stop or return errors if any clk failed to be registered, nor does it implement an error handling path. This may result in a partially working device if any step failed. Make the register function return proper error codes, and bail out if errors occur. Proper cleanup, i.e. unregister any clks that were successfully registered, is done in the new error path. 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-22-wenst@chromium.org Reviewed-by: Chun-Jie Chen <chun-jie.chen@mediatek.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent c42a288 commit 4e94ea5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

drivers/clk/mediatek/clk-cpumux.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,26 @@ int mtk_clk_register_cpumuxes(struct device_node *node,
123123
clk = mtk_clk_register_cpumux(mux, regmap);
124124
if (IS_ERR(clk)) {
125125
pr_err("Failed to register clk %s: %pe\n", mux->name, clk);
126-
continue;
126+
goto err;
127127
}
128128

129129
clk_data->clks[mux->id] = clk;
130130
}
131131

132132
return 0;
133+
134+
err:
135+
while (--i >= 0) {
136+
const struct mtk_composite *mux = &clks[i];
137+
138+
if (IS_ERR_OR_NULL(clk_data->clks[mux->id]))
139+
continue;
140+
141+
mtk_clk_unregister_cpumux(clk_data->clks[mux->id]);
142+
clk_data->clks[mux->id] = ERR_PTR(-ENOENT);
143+
}
144+
145+
return PTR_ERR(clk);
133146
}
134147

135148
void mtk_clk_unregister_cpumuxes(const struct mtk_composite *clks, int num,

0 commit comments

Comments
 (0)