David Hendricks has uploaded this change for review.

View Change

freebsd_spi: Use malloc() instead of alloca()

Change-Id: I03ff2bd1e20bea014333945771b560f17387ebd6
Signed-off-by: David Hendricks <david.hendricks@gmail.com>
---
M freebsd_spi.c
1 file changed, 7 insertions(+), 1 deletion(-)

git pull ssh://review.coreboot.org:29418/flashrom refs/changes/65/30765/1
diff --git a/freebsd_spi.c b/freebsd_spi.c
index 215be20..7514912 100644
--- a/freebsd_spi.c
+++ b/freebsd_spi.c
@@ -145,7 +145,11 @@

/* FreeBSD uses a single buffer for rx and tx. Allocate a temporary one to avoid overwriting anything. */
size_t tmpcnt = readcnt + writecnt;
- unsigned char *tmpbuf = alloca(tmpcnt);
+ unsigned char *tmpbuf = malloc(tmpcnt);
+ if (!tmpbuf) {
+ msg_perr("Out of memory!\n");
+ return -1;
+ }

bzero(tmpbuf, tmpcnt);
memcpy(tmpbuf, txbuf, writecnt);
@@ -164,12 +168,14 @@

if (ioctl(fd, SPIGENIOC_TRANSFER, &msg) == -1) {
msg_cerr("%s: ioctl: %s\n", __func__, strerror(errno));
+ free(tmpbuf);
return -1;
}

if (rxbuf)
memcpy(rxbuf, tmpbuf + writecnt, readcnt);

+ free(tmpbuf);
return 0;
}


To view, visit change 30765. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I03ff2bd1e20bea014333945771b560f17387ebd6
Gerrit-Change-Number: 30765
Gerrit-PatchSet: 1
Gerrit-Owner: David Hendricks <david.hendricks@gmail.com>
Gerrit-MessageType: newchange