Skip to content

Commit 0d6e24b

Browse files
JiangJiasbebarino
authored andcommitted
clk: mediatek: clk-mt2701: Add check for mtk_alloc_clk_data
Add the check for the return value of mtk_alloc_clk_data() in order to avoid NULL pointer dereference. Fixes: e986211 ("clk: mediatek: Add MT2701 clock support") Signed-off-by: Jiasheng Jiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Markus Schneider-Pargmann <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent 2befa51 commit 0d6e24b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/clk/mediatek/clk-mt2701.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,8 @@ static int mtk_topckgen_init(struct platform_device *pdev)
667667
return PTR_ERR(base);
668668

669669
clk_data = mtk_alloc_clk_data(CLK_TOP_NR);
670+
if (!clk_data)
671+
return -ENOMEM;
670672

671673
mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
672674
clk_data);
@@ -747,6 +749,8 @@ static void __init mtk_infrasys_init_early(struct device_node *node)
747749

748750
if (!infra_clk_data) {
749751
infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
752+
if (!infra_clk_data)
753+
return;
750754

751755
for (i = 0; i < CLK_INFRA_NR; i++)
752756
infra_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
@@ -774,6 +778,8 @@ static int mtk_infrasys_init(struct platform_device *pdev)
774778

775779
if (!infra_clk_data) {
776780
infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
781+
if (!infra_clk_data)
782+
return -ENOMEM;
777783
} else {
778784
for (i = 0; i < CLK_INFRA_NR; i++) {
779785
if (infra_clk_data->hws[i] == ERR_PTR(-EPROBE_DEFER))
@@ -890,6 +896,8 @@ static int mtk_pericfg_init(struct platform_device *pdev)
890896
return PTR_ERR(base);
891897

892898
clk_data = mtk_alloc_clk_data(CLK_PERI_NR);
899+
if (!clk_data)
900+
return -ENOMEM;
893901

894902
mtk_clk_register_gates(&pdev->dev, node, peri_clks,
895903
ARRAY_SIZE(peri_clks), clk_data);

0 commit comments

Comments
 (0)