mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Li zeming <zeming@nfschina.com>,
	"mpe@ellerman.id.au" <mpe@ellerman.id.au>,
	"npiggin@gmail.com" <npiggin@gmail.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>
Cc: "linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] boot: simple_alloc: check after increasing memory allocation
Date: Mon, 19 Dec 2022 06:42:53 +0000	[thread overview]
Message-ID: <107b0173-f0b0-adfd-10e2-e5eb76e91b92@csgroup.eu> (raw)
In-Reply-To: <20221219021816.3012-1-zeming@nfschina.com>



Le 19/12/2022 à 03:18, Li zeming a écrit :
> The pointer new adds judgment and should help with program robustness.

This text is not understandable.

Do you mean:

simple_malloc() will return NULL when there is now enough memory left.
Check pointer 'new' before using it to copy the old data.

> 
> Signed-off-by: Li zeming <zeming@nfschina.com>
> ---
>   arch/powerpc/boot/simple_alloc.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/boot/simple_alloc.c b/arch/powerpc/boot/simple_alloc.c
> index 267d6524caac..db9aaa5face3 100644
> --- a/arch/powerpc/boot/simple_alloc.c
> +++ b/arch/powerpc/boot/simple_alloc.c
> @@ -112,7 +112,9 @@ static void *simple_realloc(void *ptr, unsigned long size)
>   		return ptr;
>   
>   	new = simple_malloc(size);
> -	memcpy(new, ptr, p->size);
> +	if (new)
> +		memcpy(new, ptr, p->size);
> +
>   	simple_free(ptr);
>   	return new;
>   }

  reply	other threads:[~2022-12-19  6:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19  2:18 Li zeming
2022-12-19  6:42 ` Christophe Leroy [this message]
2024-03-13 13:19 ` Michael Ellerman

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=107b0173-f0b0-adfd-10e2-e5eb76e91b92@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=zeming@nfschina.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

all inboxes | Powered by JetHome®