summaryrefslogtreecommitdiff
path: root/util/nvmutil
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-01-28 19:39:34 +0000
committerLeah Rowe <leah@libreboot.org>2023-01-28 19:39:34 +0000
commit7e3a73558e8d1a410e225a0b102db38891a4990e (patch)
treee19da6dd05ef35b828d22c15b06641c011428cd0 /util/nvmutil
parenta924d43bdd2ad836ce275cad87a27e8c22ce2fd8 (diff)
util/nvmutil: don't use malloc()
Diffstat (limited to 'util/nvmutil')
-rw-r--r--util/nvmutil/nvmutil.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index 890d2c3f..517cbc79 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -57,8 +57,8 @@ void writeGbeFile(int *fd, const char *filename);
#define SIZE_4KB 0x1000
#define SIZE_8KB 0x2000
-uint8_t *buf = NULL;
-size_t gbe[2];
+uint8_t buf[SIZE_8KB];
+size_t gbe[2] = {(size_t) buf, ((size_t) buf) + SIZE_4KB};
uint8_t skipread[2] = {0, 0};
int part, gbeFileModified = 0;
@@ -80,10 +80,6 @@ main(int argc, char *argv[])
err(errno, "pledge");
#endif
- if ((buf = (uint8_t *) malloc(SIZE_8KB)) == NULL)
- err(errno, NULL);
- gbe[1] = (gbe[0] = (size_t) buf) + SIZE_4KB;
-
test = 1;
little_endian = ((uint8_t *) &test)[0];
@@ -402,6 +398,7 @@ word(int pos16, int partnum)
uint8_t *nbuf = (uint8_t *) gbe[partnum];
uint16_t pos8 = pos16 << 1;
uint16_t val16 = nbuf[pos8 + 1];
+
val16 <<= 8;
return val16 |= nbuf[pos8];
}
@@ -412,6 +409,7 @@ setWord(int pos16, int partnum, uint16_t val16)
uint8_t *nbuf = (uint8_t *) gbe[partnum];
uint8_t val8[2] = {(uint8_t) (val16 & 0xff), (uint8_t) (val16 >> 8)};
uint16_t pos8 = pos16 << 1;
+
nbuf[pos8] = val8[0];
nbuf[pos8 + 1] = val8[1];