Re: [PATCH 19/21] treewide: add checks for the return value of memblock_alloc*()
From: Geert Uytterhoeven <geert@linux-m68k.org>
Date: 2019-01-16 14:27:50
Also in:
linux-alpha, linux-arm-kernel, linux-devicetree, linux-mm, linux-s390, linux-um
Hi Mike, On Wed, Jan 16, 2019 at 2:46 PM Mike Rapoport [off-list ref] wrote:
Add check for the return value of memblock_alloc*() functions and call
panic() in case of error.
The panic message repeats the one used by panicing memblock allocators with
adjustment of parameters to include only relevant ones.
The replacement was mostly automated with semantic patches like the one
below with manual massaging of format strings.
@@
expression ptr, size, align;
@@
ptr = memblock_alloc(size, align);
+ if (!ptr)
+ panic("%s: Failed to allocate %lu bytes align=0x%lx\n", __func__,In general, you want to use %zu for size_t
size, align); Signed-off-by: Mike Rapoport <redacted>
Thanks for your patch!
74 files changed, 415 insertions(+), 29 deletions(-)
I'm wondering if this is really an improvement? For the normal memory allocator, the trend is to remove printing of errors from all callers, as the core takes care of that.
quoted hunk ↗ jump to hunk
--- a/arch/alpha/kernel/core_marvel.c +++ b/arch/alpha/kernel/core_marvel.c@@ -83,6 +83,9 @@ mk_resource_name(int pe, int port, char *str) sprintf(tmp, "PCI %s PE %d PORT %d", str, pe, port); name = memblock_alloc(strlen(tmp) + 1, SMP_CACHE_BYTES); + if (!name) + panic("%s: Failed to allocate %lu bytes\n", __func__,
%zu, as strlen() returns size_t.
quoted hunk ↗ jump to hunk
+ strlen(tmp) + 1); strcpy(name, tmp); return name;@@ -118,6 +121,9 @@ alloc_io7(unsigned int pe) } io7 = memblock_alloc(sizeof(*io7), SMP_CACHE_BYTES); + if (!io7) + panic("%s: Failed to allocate %lu bytes\n", __func__,
%zu, as sizeof() returns size_t.
Probably there are more. Yes, it's hard to get them right in all callers.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds