From d80d88cb87d7f291c7abc9168d69f30f994b852f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Sat, 21 Feb 2026 11:00:07 +0100 Subject: [PATCH] fw_env: allocate buffer of proper size in flash_write_buf() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When dealing with env data not aligned to flash blocks flash_write_buf() has to use an extra buffer. It reads existing flash content to it, modifies required part and writes it back. While reading and writing a size stored in "write_total" is used. It's what should be used when allocating the buffer too. In some cases allocating memory of "erase_len" size could result in allocating too big buffer. That wouldn't break anything but it was making code less intuitive. Signed-off-by: Rafał Miłecki --- tools/env/fw_env.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index c69da0b926a..fcbe09ea981 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1037,11 +1037,11 @@ static int flash_write_buf(int dev, int fd, void *buf, size_t count) * block back again. */ if (write_total > count) { - data = malloc(erase_len); + data = malloc(write_total); if (!data) { fprintf(stderr, "Cannot malloc %zu bytes: %s\n", - erase_len, strerror(errno)); + write_total, strerror(errno)); return -1; }