All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] display_options: Do not use %llu in print_size
@ 2021-08-05 21:22 Matwey V. Kornilov
  2021-08-06 16:56 ` Simon Glass
  2021-08-22 20:54 ` Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Matwey V. Kornilov @ 2021-08-05 21:22 UTC (permalink / raw)
  To: sjg, sr, trini, xypron.glpk; +Cc: u-boot, Matwey V. Kornilov

tiny-printf variant doesn't know how to handle %llu format string, but both
tiny-printf and print_size can meet in SPL when TFTP is used to obtain main
u-boot image. This is known to lead to critical boot issue at AM335x platform
when printf is catched in infinite loop.

To avoid such issues and make print_size function tiny-printf friendly, use %u
instead of %luu. Note, that the size value is guaranteed to be less than 1024
in this conditional branch, so the cast to unsigned int is safe.

Signed-off-by: Matwey V. Kornilov <matwey.kornilov@gmail.com>
---
 lib/display_options.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/display_options.c b/lib/display_options.c
index c08a87e316..4da1f5244f 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -107,7 +107,12 @@ void print_size(uint64_t size, const char *s)
 	}
 
 	if (!c) {
-		printf("%llu Bytes%s", size, s);
+		/*
+		 * SPL tiny-printf is not capable for printing uint64_t.
+		 * We have just checked that the size is small enought to fit
+		 * unsigned int safely.
+		 */
+		printf("%u Bytes%s", (unsigned int)size, s);
 		return;
 	}
 
-- 
2.31.1


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

* Re: [PATCH] display_options: Do not use %llu in print_size
  2021-08-05 21:22 [PATCH] display_options: Do not use %llu in print_size Matwey V. Kornilov
@ 2021-08-06 16:56 ` Simon Glass
  2021-08-22 20:54 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Glass @ 2021-08-06 16:56 UTC (permalink / raw)
  To: Matwey V. Kornilov
  Cc: Stefan Roese, Tom Rini, Heinrich Schuchardt, U-Boot Mailing List

On Thu, 5 Aug 2021 at 15:23, Matwey V. Kornilov
<matwey.kornilov@gmail.com> wrote:
>
> tiny-printf variant doesn't know how to handle %llu format string, but both
> tiny-printf and print_size can meet in SPL when TFTP is used to obtain main
> u-boot image. This is known to lead to critical boot issue at AM335x platform
> when printf is catched in infinite loop.
>
> To avoid such issues and make print_size function tiny-printf friendly, use %u
> instead of %luu. Note, that the size value is guaranteed to be less than 1024
> in this conditional branch, so the cast to unsigned int is safe.
>
> Signed-off-by: Matwey V. Kornilov <matwey.kornilov@gmail.com>
> ---
>  lib/display_options.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

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

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

* Re: [PATCH] display_options: Do not use %llu in print_size
  2021-08-05 21:22 [PATCH] display_options: Do not use %llu in print_size Matwey V. Kornilov
  2021-08-06 16:56 ` Simon Glass
@ 2021-08-22 20:54 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2021-08-22 20:54 UTC (permalink / raw)
  To: Matwey V. Kornilov; +Cc: sjg, sr, xypron.glpk, u-boot

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

On Fri, Aug 06, 2021 at 12:22:58AM +0300, Matwey V. Kornilov wrote:

> tiny-printf variant doesn't know how to handle %llu format string, but both
> tiny-printf and print_size can meet in SPL when TFTP is used to obtain main
> u-boot image. This is known to lead to critical boot issue at AM335x platform
> when printf is catched in infinite loop.
> 
> To avoid such issues and make print_size function tiny-printf friendly, use %u
> instead of %luu. Note, that the size value is guaranteed to be less than 1024
> in this conditional branch, so the cast to unsigned int is safe.
> 
> Signed-off-by: Matwey V. Kornilov <matwey.kornilov@gmail.com>
> 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] 3+ messages in thread

end of thread, other threads:[~2021-08-22 20:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-05 21:22 [PATCH] display_options: Do not use %llu in print_size Matwey V. Kornilov
2021-08-06 16:56 ` Simon Glass
2021-08-22 20:54 ` 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.