Skip to content

Commit 6ae34f2

Browse files
wensbebarino
authored andcommitted
clk: mediatek: pll: Implement error handling in register API
The pll 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, and unmap the I/O space, 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-26-wenst@chromium.org Reviewed-by: Chun-Jie Chen <chun-jie.chen@mediatek.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent eb7b7a7 commit 6ae34f2

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

drivers/clk/mediatek/clk-pll.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,9 @@ static void mtk_clk_unregister_pll(struct clk *clk)
377377
kfree(pll);
378378
}
379379

380-
void mtk_clk_register_plls(struct device_node *node,
381-
const struct mtk_pll_data *plls, int num_plls, struct clk_onecell_data *clk_data)
380+
int mtk_clk_register_plls(struct device_node *node,
381+
const struct mtk_pll_data *plls, int num_plls,
382+
struct clk_onecell_data *clk_data)
382383
{
383384
void __iomem *base;
384385
int i;
@@ -387,7 +388,7 @@ void mtk_clk_register_plls(struct device_node *node,
387388
base = of_iomap(node, 0);
388389
if (!base) {
389390
pr_err("%s(): ioremap failed\n", __func__);
390-
return;
391+
return -EINVAL;
391392
}
392393

393394
for (i = 0; i < num_plls; i++) {
@@ -397,11 +398,25 @@ void mtk_clk_register_plls(struct device_node *node,
397398

398399
if (IS_ERR(clk)) {
399400
pr_err("Failed to register clk %s: %pe\n", pll->name, clk);
400-
continue;
401+
goto err;
401402
}
402403

403404
clk_data->clks[pll->id] = clk;
404405
}
406+
407+
return 0;
408+
409+
err:
410+
while (--i >= 0) {
411+
const struct mtk_pll_data *pll = &plls[i];
412+
413+
mtk_clk_unregister_pll(clk_data->clks[pll->id]);
414+
clk_data->clks[pll->id] = ERR_PTR(-ENOENT);
415+
}
416+
417+
iounmap(base);
418+
419+
return PTR_ERR(clk);
405420
}
406421
EXPORT_SYMBOL_GPL(mtk_clk_register_plls);
407422

drivers/clk/mediatek/clk-pll.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ struct mtk_pll_data {
4848
u8 pll_en_bit; /* Assume 0, indicates BIT(0) by default */
4949
};
5050

51-
void mtk_clk_register_plls(struct device_node *node,
52-
const struct mtk_pll_data *plls, int num_plls,
53-
struct clk_onecell_data *clk_data);
51+
int mtk_clk_register_plls(struct device_node *node,
52+
const struct mtk_pll_data *plls, int num_plls,
53+
struct clk_onecell_data *clk_data);
5454
void mtk_clk_unregister_plls(const struct mtk_pll_data *plls, int num_plls,
5555
struct clk_onecell_data *clk_data);
5656

0 commit comments

Comments
 (0)