From mboxrd@z Thu Jan 1 00:00:00 1970 From: Geert Uytterhoeven Subject: Re: [PATCH 19/21] treewide: add checks for the return value of memblock_alloc*() Date: Wed, 16 Jan 2019 15:27:35 +0100 Message-ID: References: <1547646261-32535-1-git-send-email-rppt@linux.ibm.com> <1547646261-32535-20-git-send-email-rppt@linux.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1547646261-32535-20-git-send-email-rppt@linux.ibm.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=m.gmane.org@lists.infradead.org To: Mike Rapoport Cc: Rich Felker , "linux-ia64@vger.kernel.org" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Catalin Marinas , Heiko Carstens , the arch/x86 maintainers , linux-mips@vger.kernel.org, Max Filippov , Guo Ren , sparclinux , Christoph Hellwig , linux-s390 , linux-c6x-dev@linux-c6x.org, Yoshinori Sato , Richard Weinberger , Linux-sh list , Russell King , kasan-dev@googlegroups.com, Mark Salter , Dennis Zhou , Matt Turner , arcml List-Id: devicetree@vger.kernel.org Hi Mike, On Wed, Jan 16, 2019 at 2:46 PM Mike Rapoport 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 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@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