* [PATCH] clk: pxa: add a check for the return value of kzalloc()
@ 2022-03-25 10:27 xkernel.wang
2022-04-07 3:34 ` Stephen Boyd
0 siblings, 1 reply; 2+ messages in thread
From: xkernel.wang @ 2022-03-25 10:27 UTC (permalink / raw)
To: mturquette, sboyd; +Cc: linux-clk, linux-kernel, Xiaoke Wang
From: Xiaoke Wang <xkernel.wang@foxmail.com>
kzalloc() is a memory allocation function which can return NULL when
some internal memory errors happen. So it is better to check it to
prevent potential wrong memory access.
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
drivers/clk/pxa/clk-pxa.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clk/pxa/clk-pxa.c b/drivers/clk/pxa/clk-pxa.c
index cfc79f9..d0df104 100644
--- a/drivers/clk/pxa/clk-pxa.c
+++ b/drivers/clk/pxa/clk-pxa.c
@@ -102,6 +102,8 @@ int __init clk_pxa_cken_init(const struct desc_clk_cken *clks, int nb_clks)
for (i = 0; i < nb_clks; i++) {
pxa_clk = kzalloc(sizeof(*pxa_clk), GFP_KERNEL);
+ if (!pxa_clk)
+ continue;
pxa_clk->is_in_low_power = clks[i].is_in_low_power;
pxa_clk->lp = clks[i].lp;
pxa_clk->hp = clks[i].hp;
--
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] clk: pxa: add a check for the return value of kzalloc()
2022-03-25 10:27 [PATCH] clk: pxa: add a check for the return value of kzalloc() xkernel.wang
@ 2022-04-07 3:34 ` Stephen Boyd
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Boyd @ 2022-04-07 3:34 UTC (permalink / raw)
To: mturquette, xkernel.wang; +Cc: linux-clk, linux-kernel, Xiaoke Wang
Quoting xkernel.wang@foxmail.com (2022-03-25 03:27:20)
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> kzalloc() is a memory allocation function which can return NULL when
> some internal memory errors happen. So it is better to check it to
> prevent potential wrong memory access.
>
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
> drivers/clk/pxa/clk-pxa.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/clk/pxa/clk-pxa.c b/drivers/clk/pxa/clk-pxa.c
> index cfc79f9..d0df104 100644
> --- a/drivers/clk/pxa/clk-pxa.c
> +++ b/drivers/clk/pxa/clk-pxa.c
> @@ -102,6 +102,8 @@ int __init clk_pxa_cken_init(const struct desc_clk_cken *clks, int nb_clks)
>
> for (i = 0; i < nb_clks; i++) {
> pxa_clk = kzalloc(sizeof(*pxa_clk), GFP_KERNEL);
> + if (!pxa_clk)
> + continue;
Shouldn't we stop trying to allocate more and return an error?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-07 3:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-25 10:27 [PATCH] clk: pxa: add a check for the return value of kzalloc() xkernel.wang
2022-04-07 3:34 ` Stephen Boyd
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.