Message ID | 20221219021816.3012-1-zeming@nfschina.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 69b0194ccec033c208b071e019032c1919c2822d |
Headers | show |
Series | boot: simple_alloc: check after increasing memory allocation | expand |
Context | Check | Description |
---|---|---|
snowpatch_ozlabs/github-powerpc_selftests | success | Successfully ran 8 jobs. |
snowpatch_ozlabs/github-powerpc_ppctests | success | Successfully ran 8 jobs. |
snowpatch_ozlabs/github-powerpc_kernel_qemu | success | Successfully ran 24 jobs. |
snowpatch_ozlabs/github-powerpc_sparse | success | Successfully ran 4 jobs. |
snowpatch_ozlabs/github-powerpc_clang | success | Successfully ran 6 jobs. |
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; > }
On Mon, 19 Dec 2022 10:18:16 +0800, Li zeming wrote: > The pointer new adds judgment and should help with program robustness. > > Applied to powerpc/next. [1/1] boot: simple_alloc: check after increasing memory allocation https://git.kernel.org/powerpc/c/69b0194ccec033c208b071e019032c1919c2822d cheers
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; }
The pointer new adds judgment and should help with program robustness. Signed-off-by: Li zeming <zeming@nfschina.com> --- arch/powerpc/boot/simple_alloc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)