From: Michael Walle <mwa...@kernel.org>
Sent: Tuesday, April 1, 2025 10:56 AM
> 
> Hi,
> 
>> The issue is that disabling TINY_PRINTF may not be possible (size
>> constraints) and some code is compiled for different stages and people
>> typically don't check whether the format used in printf is valid with
>> tiny_printf. I've had this issue already in the past, I vaguely recall
>> "complaining" about it on IRC.
> 
> Yes, I've stumbled on "%pa" with tiny printf (i.e. in
> drivers/pinctrl/pinctrl-single.c) which is printing the very wrong
> value, actually :) So printing anything unknown as '?' would really
> help here.
Something like that would help:
diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
index 48db7b1f78f..b918d6d7386 100644
--- a/lib/tiny-printf.c
+++ b/lib/tiny-printf.c
@@ -280,6 +280,12 @@ static int _vprintf(struct printf_info *info, const char 
*fmt, va_list va)
                                        while (isalnum(fmt[0]))
                                                fmt++;
                                        break;
+                               } else {
+                                       if (fmt[0] != '\0' && (fmt[0] == 'a' || 
fmt[0] == 'm' ||
+                                                              fmt[0] == 'M' || 
fmt[0] == 'I')) {
+                                               fmt++;
+                                               goto unsupported;
+                                       }
                                }
                                islong = true;
                                /* no break */
@@ -308,6 +314,8 @@ static int _vprintf(struct printf_info *info, const char 
*fmt, va_list va)
                        case '%':
                                out(info, '%');
                        default:
+unsupported:
+                               out(info, '?');
                                break;
                        }

But maybe it is too much for tiny printf, because tiny means
tiny. It's a question of either gain or small code size.

Regards
Christoph

Reply via email to