Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: mediatek: clk-mt6797: 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: 96596aa06628 ("clk: mediatek: add clk support for MT6797")
Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn>
Link: https://lore.kernel.org/r/20230912093407.21505-3-jiasheng@iscas.ac.cn
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Jiasheng Jiang and committed by
Stephen Boyd
606f6366 1f57f78f

+6
+6
drivers/clk/mediatek/clk-mt6797.c
··· 390 390 return PTR_ERR(base); 391 391 392 392 clk_data = mtk_alloc_clk_data(CLK_TOP_NR); 393 + if (!clk_data) 394 + return -ENOMEM; 393 395 394 396 mtk_clk_register_factors(top_fixed_divs, ARRAY_SIZE(top_fixed_divs), 395 397 clk_data); ··· 547 545 548 546 if (!infra_clk_data) { 549 547 infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR); 548 + if (!infra_clk_data) 549 + return; 550 550 551 551 for (i = 0; i < CLK_INFRA_NR; i++) 552 552 infra_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER); ··· 574 570 575 571 if (!infra_clk_data) { 576 572 infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR); 573 + if (!infra_clk_data) 574 + return -ENOMEM; 577 575 } else { 578 576 for (i = 0; i < CLK_INFRA_NR; i++) { 579 577 if (infra_clk_data->hws[i] == ERR_PTR(-EPROBE_DEFER))