[Skiboot] [PATCH] hdata/memory: Introduce zalloc() return check

Kamalesh Babulal kamalesh at linux.vnet.ibm.com
Fri Jul 10 19:54:35 AEST 2015


In add_size_to_ram_area(), Introduce check for memory
allocation failure, before using it.

Fixes Coverity defect#97840.

Signed-off-by: Kamalesh Babulal <kamalesh at linux.vnet.ibm.com>
---
 hdata/memory.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/hdata/memory.c b/hdata/memory.c
index 6bc8695..2b440bc 100644
--- a/hdata/memory.c
+++ b/hdata/memory.c
@@ -244,6 +244,10 @@ static void add_size_to_ram_area(struct dt_node *ram_node,
 		return;
 
 	str = zalloc(kwsz + 1);
+	if (!str){
+		prerror("Allocation failed\n");
+		return;
+	}
 	memcpy(str, kw, kwsz);
 	dt_add_property_string(ram_node, "size", str);
 	free(str);
-- 
2.1.2



More information about the Skiboot mailing list