All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] malloc_simple: Remove usage of unsupported %zx format string
@ 2022-02-03 18:51 Pali Rohár
  2022-02-03 19:25 ` Sean Anderson
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Pali Rohár @ 2022-02-03 18:51 UTC (permalink / raw)
  To: Simon Glass, Tom Rini; +Cc: u-boot, Marek Behún

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

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 common/malloc_simple.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/malloc_simple.c b/common/malloc_simple.c
index 0267fb6bec87..67ee623850e0 100644
--- a/common/malloc_simple.c
+++ b/common/malloc_simple.c
@@ -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");
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] malloc_simple: Remove usage of unsupported %zx format string
  2022-02-03 18:51 [PATCH] malloc_simple: Remove usage of unsupported %zx format string Pali Rohár
@ 2022-02-03 19:25 ` Sean Anderson
  2022-02-03 19:28   ` Sean Anderson
  2022-02-03 21:19 ` Simon Glass
  2022-02-11 17:07 ` Tom Rini
  2 siblings, 1 reply; 7+ messages in thread
From: Sean Anderson @ 2022-02-03 19:25 UTC (permalink / raw)
  To: Pali Rohár, Simon Glass, Tom Rini; +Cc: u-boot, Marek Behún

Hi Pali,

On 2/3/22 1:51 PM, Pali Rohár wrote:
> 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
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>

This qualifier is implemented in vsprintf, but not tiny-printf,
and is widely used throughout the codebase. So perhaps a better
fix might be 

diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index f661fc6505..ad25bb7383 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] malloc_simple: Remove usage of unsupported %zx format string
  2022-02-03 19:25 ` Sean Anderson
@ 2022-02-03 19:28   ` Sean Anderson
  2022-02-03 21:18     ` Tom Rini
  0 siblings, 1 reply; 7+ messages in thread
From: Sean Anderson @ 2022-02-03 19:28 UTC (permalink / raw)
  To: Pali Rohár, Simon Glass, Tom Rini; +Cc: u-boot, Marek Behún



On 2/3/22 2:25 PM, Sean Anderson wrote:
> Hi Pali,
> 
> On 2/3/22 1:51 PM, Pali Rohár wrote:
>> 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
>> 
>> Signed-off-by: Pali Rohár <pali@kernel.org>
> 
> This qualifier is implemented in vsprintf, but not tiny-printf,
> and is widely used throughout the codebase. So perhaps a better
> fix might be 
> 
> diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
> index f661fc6505..ad25bb7383 100644
> --- a/lib/tiny-printf.c
> +++ b/lib/tiny-printf.c
> @@ -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.

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] malloc_simple: Remove usage of unsupported %zx format string
  2022-02-03 19:28   ` Sean Anderson
@ 2022-02-03 21:18     ` Tom Rini
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Rini @ 2022-02-03 21:18 UTC (permalink / raw)
  To: Sean Anderson; +Cc: Pali Rohár, Simon Glass, u-boot, Marek Behún

[-- Attachment #1: Type: text/plain, Size: 1991 bytes --]

On Thu, Feb 03, 2022 at 02:28:23PM -0500, Sean Anderson wrote:
> 
> 
> On 2/3/22 2:25 PM, Sean Anderson wrote:
> > Hi Pali,
> > 
> > On 2/3/22 1:51 PM, Pali Rohár wrote:
> >> 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
> >> 
> >> Signed-off-by: Pali Rohár <pali@kernel.org>
> > 
> > This qualifier is implemented in vsprintf, but not tiny-printf,
> > and is widely used throughout the codebase. So perhaps a better
> > fix might be 
> > 
> > diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
> > index f661fc6505..ad25bb7383 100644
> > --- a/lib/tiny-printf.c
> > +++ b/lib/tiny-printf.c
> > @@ -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.
> 
> 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.

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.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] malloc_simple: Remove usage of unsupported %zx format string
  2022-02-03 18:51 [PATCH] malloc_simple: Remove usage of unsupported %zx format string Pali Rohár
  2022-02-03 19:25 ` Sean Anderson
@ 2022-02-03 21:19 ` Simon Glass
  2022-02-04 10:48   ` Pali Rohár
  2022-02-11 17:07 ` Tom Rini
  2 siblings, 1 reply; 7+ messages in thread
From: Simon Glass @ 2022-02-03 21:19 UTC (permalink / raw)
  To: Pali Rohár; +Cc: Tom Rini, U-Boot Mailing List, Marek Behún

Hi Pali,

On Thu, 3 Feb 2022 at 11:51, Pali Rohár <pali@kernel.org> wrote:
>
> Replace %zx by %lx and cast size_t to ulong.
>
> U-Boot currently prints garbage debug output:
> size=x, ptr=18, limit=18: 4002a000

Do you mean in SPL?

>
> With this change it prints correct debug data:
> size=18, ptr=18, limit=2000: 4002a000
>
> Signed-off-by: Pali Rohár <pali@kernel.org>
> ---
>  common/malloc_simple.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

> diff --git a/common/malloc_simple.c b/common/malloc_simple.c
> index 0267fb6bec87..67ee623850e0 100644
> --- a/common/malloc_simple.c
> +++ b/common/malloc_simple.c
> @@ -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");
> --
> 2.20.1
>

Regards,
Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] malloc_simple: Remove usage of unsupported %zx format string
  2022-02-03 21:19 ` Simon Glass
@ 2022-02-04 10:48   ` Pali Rohár
  0 siblings, 0 replies; 7+ messages in thread
From: Pali Rohár @ 2022-02-04 10:48 UTC (permalink / raw)
  To: Simon Glass; +Cc: Tom Rini, U-Boot Mailing List, Marek Behún

On Thursday 03 February 2022 14:19:41 Simon Glass wrote:
> Hi Pali,
> 
> On Thu, 3 Feb 2022 at 11:51, Pali Rohár <pali@kernel.org> wrote:
> >
> > Replace %zx by %lx and cast size_t to ulong.
> >
> > U-Boot currently prints garbage debug output:
> > size=x, ptr=18, limit=18: 4002a000
> 
> Do you mean in SPL?

Yes, this is printed in 32-bit mvebu SPL.

> >
> > With this change it prints correct debug data:
> > size=18, ptr=18, limit=2000: 4002a000
> >
> > Signed-off-by: Pali Rohár <pali@kernel.org>
> > ---
> >  common/malloc_simple.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>
> 
> > diff --git a/common/malloc_simple.c b/common/malloc_simple.c
> > index 0267fb6bec87..67ee623850e0 100644
> > --- a/common/malloc_simple.c
> > +++ b/common/malloc_simple.c
> > @@ -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");
> > --
> > 2.20.1
> >
> 
> Regards,
> Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] malloc_simple: Remove usage of unsupported %zx format string
  2022-02-03 18:51 [PATCH] malloc_simple: Remove usage of unsupported %zx format string Pali Rohár
  2022-02-03 19:25 ` Sean Anderson
  2022-02-03 21:19 ` Simon Glass
@ 2022-02-11 17:07 ` Tom Rini
  2 siblings, 0 replies; 7+ messages in thread
From: Tom Rini @ 2022-02-11 17:07 UTC (permalink / raw)
  To: Pali Rohár; +Cc: Simon Glass, u-boot, Marek Behún

[-- Attachment #1: Type: text/plain, Size: 444 bytes --]

On Thu, Feb 03, 2022 at 07:51:37PM +0100, Pali Rohár wrote:

> 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
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-02-11 17:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-03 18:51 [PATCH] malloc_simple: Remove usage of unsupported %zx format string Pali Rohár
2022-02-03 19:25 ` Sean Anderson
2022-02-03 19:28   ` Sean Anderson
2022-02-03 21:18     ` Tom Rini
2022-02-03 21:19 ` Simon Glass
2022-02-04 10:48   ` Pali Rohár
2022-02-11 17:07 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.