]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
common: fix behavior of ROUND macro when input is already rounded
authorAnton Staaf <robotboy@chromium.org>
Fri, 2 Sep 2011 13:45:28 +0000 (13:45 +0000)
committerWolfgang Denk <wd@denx.de>
Wed, 7 Sep 2011 21:39:36 +0000 (23:39 +0200)
Currently when you call ROUND with a value that is already a
multiple of the second parameter it will return a value that is
one multiple larger, instead of returning the value passed in.

There are only two types of usage of ROUND currently, one in
various config files to round CONFIG_SYS_MALLOC_LEN to a multiple
of 4096 bytes.  The other in cmd_sf.c where the incorrect behavior
of ROUND is worked around be subtracting one from the length argument
before passing it to ROUND.

This patch fixes ROUND and removes the workaround from cmd_sf.  It
also results in all of the malloc pools that use ROUND to compute
their size shrinking by 4KB.

Cc: Lukasz Majewski <l.majewski@samsung.com>
Cc: Mike Frysinger <vapier@gentoo.org>
common/cmd_sf.c
include/common.h

index 11a491df769fc81206d9dfe82584b443e468c029..27d6e39a18dbaa825e0ba5b7ab9092511d6b8381 100644 (file)
@@ -53,7 +53,7 @@ static int sf_parse_len_arg(char *arg, ulong *len)
                return -1;
 
        if (round_up_len && flash->sector_size > 0)
-               *len = ROUND(len_arg - 1, flash->sector_size);
+               *len = ROUND(len_arg, flash->sector_size);
        else
                *len = len_arg;
 
index bd10f31f847f74c2bda7515e5f4f461d846cfca7..af8b154fd54d063fbe74d4008860f0e1d18b0f3b 100644 (file)
@@ -760,7 +760,7 @@ int cpu_release(int nr, int argc, char * const argv[]);
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
-#define ROUND(a,b)             (((a) + (b)) & ~((b) - 1))
+#define ROUND(a,b)             (((a) + (b) - 1) & ~((b) - 1))
 #define DIV_ROUND(n,d)         (((n) + ((d)/2)) / (d))
 #define DIV_ROUND_UP(n,d)      (((n) + (d) - 1) / (d))
 #define roundup(x, y)          ((((x) + ((y) - 1)) / (y)) * (y))