* [U-Boot] [PATCH] common: fix behavior of ROUND macro when input is already rounded
@ 2011-09-02 23:45 Anton Staaf
2011-09-07 21:39 ` Wolfgang Denk
0 siblings, 1 reply; 2+ messages in thread
From: Anton Staaf @ 2011-09-02 23:45 UTC (permalink / raw)
To: u-boot
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>
---
I'm not sure if it makes sense to go and add 4KB to each malloc pool effected. What do other people think? I'd be happy to make a v2 that does that. This just seemed like a cleaner v1 to start with.
common/cmd_sf.c | 2 +-
include/common.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 11a491d..27d6e39 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -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;
diff --git a/include/common.h b/include/common.h
index 12a1074..3f49fef 100644
--- a/include/common.h
+++ b/include/common.h
@@ -759,7 +759,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))
--
1.7.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] [PATCH] common: fix behavior of ROUND macro when input is already rounded
2011-09-02 23:45 [U-Boot] [PATCH] common: fix behavior of ROUND macro when input is already rounded Anton Staaf
@ 2011-09-07 21:39 ` Wolfgang Denk
0 siblings, 0 replies; 2+ messages in thread
From: Wolfgang Denk @ 2011-09-07 21:39 UTC (permalink / raw)
To: u-boot
Dear Anton Staaf,
In message <1315007128-10710-1-git-send-email-robotboy@chromium.org> you wrote:
> 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>
> ---
>
> I'm not sure if it makes sense to go and add 4KB to each malloc pool effected. What do other people think? I'd be happy to make a v2 that does that. This just seemed like a cleaner v1 to start with.
>
> common/cmd_sf.c | 2 +-
> include/common.h | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"There are three principal ways to lose money: wine, women, and engi-
neers. While the first two are more pleasant, the third is by far the
more certain." - Baron Rothschild, ca. 1800
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-09-07 21:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-02 23:45 [U-Boot] [PATCH] common: fix behavior of ROUND macro when input is already rounded Anton Staaf
2011-09-07 21:39 ` Wolfgang Denk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox