[OpenRISC] [PATCH 19/21] treewide: add checks for the return value of memblock_alloc*()

Geert Uytterhoeven
2019-01-16T14:27:35Z

Hi Mike,

On Wed, Jan 16, 2019 at 2:46 PM Mike Rapoport <rppt@linux.ibm.com> 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 <rppt@linux.ibm.com>

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.

> --- 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.

> + 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 at 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