Skip to contentSkip to conversation

x86, olpc: Eliminate BUG_ON and memset after alloc_bootmem

PATCH In review Himangi Saraogi 2 participants 2 messages Jul 19, 2014 – Jul 21, 2014 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, olpc: Eliminate BUG_ON and memset after alloc_bootmem

alloc_bootmem and related functions never return NULL and always return a zeroed region of memory. Thus a BUG_ON the NULL test or memset after calls to these functions is unnecessary.

The following Coccinelle semantic patch was used for making the change:

@@
expression E;
statement S;
@@

E = \(alloc_bootmem\|alloc_bootmem_low\|alloc_bootmem_pages\|alloc_bootmem_low_pages\)(...) ... when != E
- BUG_ON (E == NULL);

@@
expression E,E1;
@@

E = \(alloc_bootmem\|alloc_bootmem_low\|alloc_bootmem_pages\|alloc_bootmem_low_pages\)(...) ... when != E
- memset(E,0,E1);

---
 arch/x86/platform/olpc/olpc_dt.c | 2 --
 1 file changed, 2 deletions(-)
arch/x86/platform/olpc/olpc_dt.c +0 -2
index d6ee929..280645d 100644
@@ -142,9 +142,7 @@ void * __init prom_early_alloc(unsigned long size)
 		 * wasted bootmem) and hand off chunks of it to callers.
 		 */
 		res = alloc_bootmem(chunk_size);
-		BUG_ON(!res);
 		prom_early_allocated += chunk_size;
-		memset(res, 0, chunk_size);
 		free_mem = chunk_size;
 		mem = res;
 	}
Signature · 1 line
1.9.1
Acked-by on v1 1/1
#1 lore raw
Quoted 19 lines · Himangi Saraogi

alloc_bootmem and related functions never return NULL and always return a zeroed region of memory. Thus a BUG_ON the NULL test or memset after calls to these functions is unnecessary.

The following Coccinelle semantic patch was used for making the change:

@@
expression E;
statement S;
@@

E = \(alloc_bootmem\|alloc_bootmem_low\|alloc_bootmem_pages\|alloc_bootmem_low_pages\)(...) ... when != E
- BUG_ON (E == NULL);

@@
expression E,E1;
@@

Quoted 6 lines

E = \(alloc_bootmem\|alloc_bootmem_low\|alloc_bootmem_pages\|alloc_bootmem_low_pages\)(...) ... when != E
- memset(E,0,E1);

Many callers of alloc_bootmem() do not check for the return value because of this, there's no fallback available at this part in bootstrap so there's nothing else that can be done.