Thread (35 messages) 35 messages, 10 authors, 2019-01-18

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

From: Heiko Carstens <hidden>
Date: 2019-01-18 08:43:28
Also in: linux-alpha, linux-arm-kernel, linux-devicetree, linux-mips, linux-mm, linux-s390, linux-sh, linux-um, linux-usb, lkml, sparclinux

On Wed, Jan 16, 2019 at 03:44:19PM +0200, 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__,
size, align);

Signed-off-by: Mike Rapoport <redacted>
...
quoted hunk ↗ jump to hunk
diff --git a/arch/s390/numa/toptree.c b/arch/s390/numa/toptree.c
index 71a608c..0118c77 100644
--- a/arch/s390/numa/toptree.c
+++ b/arch/s390/numa/toptree.c
@@ -31,10 +31,14 @@ struct toptree __ref *toptree_alloc(int level, int id)
 {
 	struct toptree *res;

-	if (slab_is_available())
+	if (slab_is_available()) {
 		res = kzalloc(sizeof(*res), GFP_KERNEL);
-	else
+	} else {
 		res = memblock_alloc(sizeof(*res), 8);
+		if (!res)
+			panic("%s: Failed to allocate %zu bytes align=0x%x\n",
+			      __func__, sizeof(*res), 8);
+	}
 	if (!res)
 		return res;
Please remove this hunk, since the code _should_ be able to handle
allocation failures anyway (see end of quoted code).

Otherwise for the s390 bits:
Acked-by: Heiko Carstens <redacted>
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help