summaryrefslogtreecommitdiff
path: root/bitbang_spi.c
diff options
context:
space:
mode:
authorhailfinger <hailfinger@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1>2009-11-25 16:58:17 +0000
committerhailfinger <hailfinger@2b7e53f0-3cfb-0310-b3e9-8179ed1497e1>2009-11-25 16:58:17 +0000
commit7514a58723a96fd1fa7b26e3a9d653d0f9e64840 (patch)
tree341176081702d03d5bfc3fc5eafbeea6618f5e0c /bitbang_spi.c
parent2e7db9459839e3604e6ad76f0e24fd3f1a402f7e (diff)
downloadflashrom-7514a58723a96fd1fa7b26e3a9d653d0f9e64840.tar.gz
Reduce realloc syscall overhead for FT2232 and bitbang.
FT2232 ran realloc() for every executed command. Start with a big enough buffer and don't touch buffer size unless it needs to grow. Bitbang was slightly better: It only ran realloc() if buffer size changed. Still, the solution above improves performance and reliability. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Sean Nelson <audiohacked@gmail.com> git-svn-id: https://code.coreboot.org/svn/flashrom/trunk@780 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'bitbang_spi.c')
-rw-r--r--bitbang_spi.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/bitbang_spi.c b/bitbang_spi.c
index 0f1f7ed..abf5530 100644
--- a/bitbang_spi.c
+++ b/bitbang_spi.c
@@ -87,14 +87,16 @@ int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt,
static unsigned char *bufout = NULL;
static unsigned char *bufin = NULL;
static int oldbufsize = 0;
- int bufsize = max(writecnt + readcnt, 260);
+ int bufsize;
int i;
/* Arbitrary size limitation here. We're only constrained by memory. */
if (writecnt > 65536 || readcnt > 65536)
return SPI_INVALID_LENGTH;
- if (bufsize != oldbufsize) {
+ bufsize = max(writecnt + readcnt, 260);
+ /* Never shrink. realloc() calls are expensive. */
+ if (bufsize > oldbufsize) {
bufout = realloc(bufout, bufsize);
if (!bufout) {
fprintf(stderr, "Out of memory!\n");
@@ -109,6 +111,7 @@ int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt,
free(bufout);
exit(1);
}
+ oldbufsize = bufsize;
}
memcpy(bufout, writearr, writecnt);