Skip to contentSkip to conversation

tile: add null check for kzalloc in tile/kernel/setup.c

PATCH In review Wang Sheng-Hui 2 participants 2 messages Aug 22, 2013 – Aug 29, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tile: add null check for kzalloc in tile/kernel/setup.c

Should check the return value of kzalloc first to avoid the null pointer. Then can dereference the non-null pointer to access the fields of struct resource.

---
 arch/tile/kernel/setup.c |    4 ++++
 1 file changed, 4 insertions(+)
arch/tile/kernel/setup.c +4 -0
index eceb834..7d4138c 100644
@@ -1548,6 +1548,8 @@ insert_non_bus_resource(void)
 {
 	struct resource *res =
 		kzalloc(sizeof(struct resource), GFP_ATOMIC);
+	if (!res)
+		return NULL;
 	res->name = "Non-Bus Physical Address Space";
 	res->start = (1ULL << 32);
 	res->end = -1LL;
@@ -1565,6 +1567,8 @@ insert_ram_resource(u64 start_pfn, u64 end_pfn)
 {
 	struct resource *res =
 		kzalloc(sizeof(struct resource), GFP_ATOMIC);
+	if (!res)
+		return NULL;
 	res->name = "System RAM";
 	res->start = start_pfn << PAGE_SHIFT;
 	res->end = (end_pfn << PAGE_SHIFT) - 1;
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 7 lines · Wang Sheng-Hui

Should check the return value of kzalloc first to avoid the null pointer. Then can dereference the non-null pointer to access the fields of struct resource.

---
 arch/tile/kernel/setup.c |    4 ++++
 1 file changed, 4 insertions(+)

Thanks. Taken into the tile tree.

Signature · 2 lines
Chris Metcalf, Tilera Corp.
http://www.tilera.com