nvmutil: explain a few parts in nvmalloc

the current code is optimised for speed, but it's a bit
esoteric, so make it easier to understand.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-02-23 11:13:09 +00:00
parent 061e6048a8
commit 50de561ac4
+5
View File
@@ -197,19 +197,24 @@ openFiles(const char *path)
void
nvmalloc(void)
{
/* same operations need the full block, others only 128 bytes */
if ((cmd == cmd_swap) || (cmd == cmd_copy))
nf = SIZE_4KB;
else
nf = NVM_SIZE;
/* only read the part specified, for copy/setchecksum/brick */
if ((cmd == cmd_copy) || (cmd == cmd_setchecksum) || (cmd == cmd_brick))
do_read[part ^ 1] = 0;
/* only allocate one block if only one part being read */
char *buf = malloc(nf << (do_read[0] & do_read[1]));
if (buf == NULL)
err(errno, NULL);
gbe[0] = (size_t) buf;
/* speedhack: for cmd copy, both pointers are set the same */
gbe[1] = gbe[0] + (nf * (do_read[0] & do_read[1]));
}