Skip to content

Commit eb7b7a7

Browse files
wensbebarino
authored andcommitted
clk: mediatek: mux: Implement error handling in register API
The mux 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-25-wenst@chromium.org Reviewed-by: Chun-Jie Chen <chun-jie.chen@mediatek.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent 203ce39 commit eb7b7a7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

drivers/clk/mediatek/clk-mux.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,26 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes,
215215

216216
if (IS_ERR(clk)) {
217217
pr_err("Failed to register clk %s: %pe\n", mux->name, clk);
218-
continue;
218+
goto err;
219219
}
220220

221221
clk_data->clks[mux->id] = clk;
222222
}
223223

224224
return 0;
225+
226+
err:
227+
while (--i >= 0) {
228+
const struct mtk_mux *mux = &muxes[i];
229+
230+
if (IS_ERR_OR_NULL(clk_data->clks[mux->id]))
231+
continue;
232+
233+
mtk_clk_unregister_mux(clk_data->clks[mux->id]);
234+
clk_data->clks[mux->id] = ERR_PTR(-ENOENT);
235+
}
236+
237+
return PTR_ERR(clk);
225238
}
226239
EXPORT_SYMBOL_GPL(mtk_clk_register_muxes);
227240

0 commit comments

Comments
 (0)