summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2025-01-26 07:05:06 +0000
committerLeah Rowe <leah@libreboot.org>2025-01-26 07:05:06 +0000
commit52e8ea57f7b1cef262939696e8012835dc4f7e59 (patch)
tree17739414e526d4033281bc327fb82f7ad55aea6b
parent7a7d356824e436d3df41c84de59ca30e5d95be6b (diff)
util/nvmutil: Further reduce memory usage
Allocate memory based on nf instead of partsize. nf is the number of bytes actually read from each part of the file. Now if the user is running setmac for example, 256 bytes of memory will be allocated regardless of gbe file size, whereas it would have previously allocated 8KB, 16KB or 128KB depending on the file. Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--util/nvmutil/nvmutil.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/util/nvmutil/nvmutil.c b/util/nvmutil/nvmutil.c
index abb55602..9b672ae0 100644
--- a/util/nvmutil/nvmutil.c
+++ b/util/nvmutil/nvmutil.c
@@ -198,10 +198,6 @@ openFiles(const char *path)
void
readGbe(void)
{
- char *buf = malloc(partsize << 1);
- if (buf == NULL)
- err(errno, "Can't malloc %ld B for '%s'", partsize, filename);
-
if ((cmd == writeGbe) || (cmd == cmd_copy))
nf = partsize; /* read/write the entire block */
else
@@ -210,9 +206,13 @@ readGbe(void)
if ((cmd == cmd_copy) || (cmd == cmd_setchecksum) || (cmd == cmd_brick))
skipread[part ^ 1] = 1; /* only read the user-specified part */
+ char *buf = malloc(nf << 1);
+ if (buf == NULL)
+ err(errno, "Can't malloc %ld B for '%s'", partsize, filename);
+
/* we pread per-part, so each part has its own pointer: */
gbe[0] = (size_t) buf;
- gbe[1] = gbe[0] + partsize;
+ gbe[1] = gbe[0] + nf;
for (int p = 0; p < 2; p++) {
if (skipread[p])