Skip to content

Commit e938a13

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

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

drivers/clk/mediatek/clk-gate.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,26 @@ int mtk_clk_register_gates_with_dev(struct device_node *node,
237237

238238
if (IS_ERR(clk)) {
239239
pr_err("Failed to register clk %s: %pe\n", gate->name, clk);
240-
continue;
240+
goto err;
241241
}
242242

243243
clk_data->clks[gate->id] = clk;
244244
}
245245

246246
return 0;
247+
248+
err:
249+
while (--i >= 0) {
250+
const struct mtk_gate *gate = &clks[i];
251+
252+
if (IS_ERR_OR_NULL(clk_data->clks[gate->id]))
253+
continue;
254+
255+
mtk_clk_unregister_gate(clk_data->clks[gate->id]);
256+
clk_data->clks[gate->id] = ERR_PTR(-ENOENT);
257+
}
258+
259+
return PTR_ERR(clk);
247260
}
248261

249262
int mtk_clk_register_gates(struct device_node *node,

0 commit comments

Comments
 (0)