]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
fw_env: add ROUND_UP() helper
authorRafał Miłecki <rafal@milecki.pl>
Sat, 21 Feb 2026 10:00:08 +0000 (11:00 +0100)
committerTom Rini <trini@konsulko.com>
Fri, 6 Mar 2026 16:32:41 +0000 (10:32 -0600)
We already have DIV_ROUND_UP() to simplify code so add ROUND_UP() as
well. This makes code in flash_write_buf() easier to follow.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
tools/env/fw_env.c

index fcbe09ea98119ac214417ff6ae4de3e1410875bb..c369bda1b858af65dbf656a0d8207de29cf4801b 100644 (file)
@@ -50,6 +50,7 @@ struct env_opts default_opts = {
 };
 
 #define DIV_ROUND_UP(n, d)     (((n) + (d) - 1) / (d))
+#define ROUND_UP(x, y)         (DIV_ROUND_UP(x, y) * (y))
 
 #define min(x, y) ({                           \
        typeof(x) _min1 = (x);                  \
@@ -1027,8 +1028,7 @@ static int flash_write_buf(int dev, int fd, void *buf, size_t count)
                 * to the start of the data, then count bytes of data, and
                 * to the end of the block
                 */
-               write_total = ((block_seek + count + blocklen - 1) /
-                              blocklen) * blocklen;
+               write_total = ROUND_UP(block_seek + count, blocklen);
        }
 
        /*