Skip to contentSkip to conversation

fdtoverlay: Switch from using alloca to malloc

PATCH Applied [email protected] 2 participants 2 messages Jan 3, 2018 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fdtoverlay: Switch from using alloca to malloc

alloca entails a complicated header situation when using other platforms, where some split it out in alloca.h while others include it as a standard part of stdlib.h.

The cons don't seem to outweigh the pros, so switch it to malloc.

---
 fdtoverlay.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fdtoverlay.c +2 -2
index 7f124fc..62a942d 100644
@@ -26,7 +26,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <alloca.h>
 #include <inttypes.h>
 
 #include <libfdt.h>
@@ -79,7 +78,7 @@ static int do_fdtoverlay(const char *input_filename,
 	ret = 0;
 
 	/* allocate blob pointer array */
-	ovblob = alloca(sizeof(*ovblob) * argc);
+	ovblob = malloc(sizeof(*ovblob) * argc);
 	memset(ovblob, 0, sizeof(*ovblob) * argc);
 
 	/* read and keep track of the overlay blobs */
@@ -121,6 +120,7 @@ out_err:
 			if (ovblob[i])
 				free(ovblob[i]);
 		}
+		free(ovblob);
 	}
 	free(blob);
 
Signature · 1 line
2.15.1

A message that is not in the archive (sent off-list or not yet received): 20180103030538.46326-1-kevans-HZy0K5TPuP5AfugRpC6u6w@public.gmane.org

Applied
#2 lore raw
Quoted 7 lines · On Tue, Jan 02, 2018 at 09:05:38PM -0600…

alloca entails a complicated header situation when using other platforms, where some split it out in alloca.h while others include it as a standard part of stdlib.h.

The cons don't seem to outweigh the pros, so switch it to malloc.

Applied, thanks.

Quoted 33 lines
---
 fdtoverlay.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fdtoverlay.c +2 -2
index 7f124fc..62a942d 100644
@@ -26,7 +26,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <alloca.h>
 #include <inttypes.h>
 
 #include <libfdt.h>
@@ -79,7 +78,7 @@ static int do_fdtoverlay(const char *input_filename,
 	ret = 0;
 
 	/* allocate blob pointer array */
-	ovblob = alloca(sizeof(*ovblob) * argc);
+	ovblob = malloc(sizeof(*ovblob) * argc);
 	memset(ovblob, 0, sizeof(*ovblob) * argc);
 
 	/* read and keep track of the overlay blobs */
@@ -121,6 +120,7 @@ out_err:
 			if (ovblob[i])
 				free(ovblob[i]);
 		}
+		free(ovblob);
 	}
 	free(blob);
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson