Message ID | 20210805212258.11027-1-matwey.kornilov@gmail.com |
---|---|
State | Accepted |
Commit | f52352f65e359c91f69faaa6f6cd1ea34f8adf6d |
Headers | show |
Series | display_options: Do not use %llu in print_size | expand |
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>
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
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; }
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(-) -- 2.31.1