public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Boyd <sboyd@kernel.org>
To: mturquette@baylibre.com, xkernel.wang@foxmail.com
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	Xiaoke Wang <xkernel.wang@foxmail.com>
Subject: Re: [PATCH] clk: pxa: add a check for the return value of kzalloc()
Date: Wed, 06 Apr 2022 20:34:07 -0700	[thread overview]
Message-ID: <20220407033409.DC889C385A1@smtp.kernel.org> (raw)
In-Reply-To: <tencent_C0622B5C4209E83F1C6495D926979F239D05@qq.com>

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?

      reply	other threads:[~2022-04-07  3:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220407033409.DC889C385A1@smtp.kernel.org \
    --to=sboyd@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=xkernel.wang@foxmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox