malloc_simple: Remove usage of unsupported %zx format string
PATCH 1/1 malloc_simple: Remove usage of unsupported %zx format string
Replace %zx by %lx and cast size_t to ulong.
U-Boot currently prints garbage debug output:
size=x, ptr=18, limit=18: 4002a000
With this change it prints correct debug data:
size=18, ptr=18, limit=2000: 4002a000
--- common/malloc_simple.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
common/malloc_simple.c +1 -1
@@ -23,7 +23,7 @@ static void *alloc_simple(size_t bytes, int align) addr =ALIGN (gd->malloc_base + gd->malloc_ptr, align); new_ptr = addr + bytes - gd->malloc_base; -log_debug ("size=%zx, ptr=%lx, limit=%lx: " , bytes, new_ptr, +log_debug ("size=%lx, ptr=%lx, limit=%lx: " , (ulong )bytes, new_ptr, gd->malloc_limit);if (new_ptr > gd->malloc_limit) {log_err ("alloc space exhausted\n" );
Signature · 1 line
2.20.1
Hi Pali,
Quoted 9 lines · Pali Rohár
Replace %zx by %lx and cast
size_tto ulong.U-Boot currently prints garbage debug output:
size=x, ptr=18, limit=18:4002a000With this change it prints correct debug data:
size=18, ptr=18, limit=2000:4002a000Signed-off-by Pali Rohár <[email protected]>
This qualifier is implemented in vsprintf, but not tiny-printf, and is widely used throughout the codebase. So perhaps a better fix might be
lib/tiny-printf.c +2 -1
@@ -229,7 +229,8 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va) ch = *fmt++; } } -if (ch =='l' ) { +if (ch =='l' || + (sizeof (size_t ) >=sizeof (int ) && ch =='z' )) { ch = *(fmt++); islong = true; }
--
which is not completely correct (since tiny-printf doesn't support long longs), but will address the core issue.
--Sean
Quoted 33 lines · Sean Anderson
Hi Pali,
Quoted 9 lines · Pali Rohár
Replace %zx by %lx and cast
size_tto ulong.U-Boot currently prints garbage debug output:
size=x, ptr=18, limit=18:4002a000With this change it prints correct debug data:
size=18, ptr=18, limit=2000:4002a000Signed-off-by Pali Rohár <[email protected]>This qualifier is implemented in vsprintf, but not tiny-printf, and is widely used throughout the codebase. So perhaps a better fix might be
lib/tiny-printf.c +2
-2@@ -229,7 +229,8 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va) ch = *fmt++; } } -if (ch =='l' ) { +if (ch =='l' || + (sizeof (size_t ) >=sizeof (int ) && ch =='z' )) { ch = *(fmt++); islong = true; } --
Quoted 2 lines
which is not completely correct (since tiny-printf doesn't support long longs), but will address the core issue.
Actually, we probably need something more like
if (ch == 'z') {
ch = *(fmt++);
islong = sizeof(size_t) >= sizeof(int);
}so that 32-bit arches still print the integer.
--Sean
Quoted 41 lines · Sean Anderson
Quoted 33 lines · Sean Anderson
Hi Pali,
Quoted 9 lines · Pali Rohár
Replace %zx by %lx and cast
size_tto ulong.U-Boot currently prints garbage debug output:
size=x, ptr=18, limit=18:4002a000With this change it prints correct debug data:
size=18, ptr=18, limit=2000:4002a000Signed-off-by Pali Rohár <[email protected]>This qualifier is implemented in vsprintf, but not tiny-printf, and is widely used throughout the codebase. So perhaps a better fix might be
lib/tiny-printf.c +2
-2@@ -229,7 +229,8 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va) ch = *fmt++; } } -if (ch =='l' ) { +if (ch =='l' || + (sizeof (size_t ) >=sizeof (int ) && ch =='z' )) { ch = *(fmt++); islong = true; } --Quoted 2 lines
which is not completely correct (since tiny-printf doesn't support long longs), but will address the core issue.
Actually, we probably need something more like
Quoted 6 lines
if (ch == 'z') { ch = *(fmt++); islong = sizeof(size_t) >= sizeof(int); }so that 32-bit arches still print the integer.
Right, but then we grow tiny-printf on the boards that really need to be super concerned about space. We have typically done what Pali proposes here before of make the subset of code that runs under tiny-printf use more restrictive and possibly slightly less optimal format characters.
Signature · 1 line
Tom
Hi Pali,
Quoted 5 lines · Pali Rohár
Replace %zx by %lx and cast
size_tto ulong.U-Boot currently prints garbage debug output:
size=x, ptr=18, limit=18:4002a000
Do you mean in SPL?
Quoted 9 lines
With this change it prints correct debug data:
size=18, ptr=18, limit=2000:4002a000Signed-off-by Pali Rohár <[email protected]>--- common/malloc_simple.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
common/malloc_simple.c +1
-2@@ -23,7 +23,7 @@ static void *alloc_simple(size_t bytes, int align) addr =ALIGN (gd->malloc_base + gd->malloc_ptr, align); new_ptr = addr + bytes - gd->malloc_base; -log_debug ("size=%zx, ptr=%lx, limit=%lx: " , bytes, new_ptr, +log_debug ("size=%lx, ptr=%lx, limit=%lx: " , (ulong )bytes, new_ptr, gd->malloc_limit);if (new_ptr > gd->malloc_limit) {log_err ("alloc space exhausted\n" ); --
Quoted 2 lines
2.20.1
Regards,
Simon
Quoted 10 lines · On Thursday 03 February 2022 14:19:41 Simon Glass wrote:
Hi Pali,
Quoted 5 lines · Pali Rohár
Replace %zx by %lx and cast
size_tto ulong.U-Boot currently prints garbage debug output:
size=x, ptr=18, limit=18:4002a000Do you mean in SPL?
Yes, this is printed in 32-bit mvebu SPL.
Quoted 31 lines
Quoted 9 lines
With this change it prints correct debug data:
size=18, ptr=18, limit=2000:4002a000Signed-off-by Pali Rohár <[email protected]>--- common/malloc_simple.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Reviewed-by Simon Glass <[email protected]>Quoted 14 lines
common/malloc_simple.c +1
-2@@ -23,7 +23,7 @@ static void *alloc_simple(size_t bytes, int align) addr =ALIGN (gd->malloc_base + gd->malloc_ptr, align); new_ptr = addr + bytes - gd->malloc_base; -log_debug ("size=%zx, ptr=%lx, limit=%lx: " , bytes, new_ptr, +log_debug ("size=%lx, ptr=%lx, limit=%lx: " , (ulong )bytes, new_ptr, gd->malloc_limit);if (new_ptr > gd->malloc_limit) {log_err ("alloc space exhausted\n" ); --Quoted 2 lines
2.20.1
Regards,
Simon
Quoted 10 lines · Pali Rohár
Replace %zx by %lx and cast
size_tto ulong.U-Boot currently prints garbage debug output:
size=x, ptr=18, limit=18:4002a000With this change it prints correct debug data:
size=18, ptr=18, limit=2000:4002a000Signed-off-by Pali Rohár <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom