diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2020-09-28 17:34:29 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-09-29 08:41:53 +0200 |
commit | 91084b450226f22a8c6fee5a5762a4d0f44a18f4 (patch) | |
tree | 1964a773a70fd8e7e853627d6f2513de07d51d92 | |
parent | 94b0c3f8635a6560ed387c957331fe1d720fe775 (diff) | |
download | barebox-91084b450226f22a8c6fee5a5762a4d0f44a18f4.tar.gz barebox-91084b450226f22a8c6fee5a5762a4d0f44a18f4.tar.xz |
vsprintf: add %pe format specifier for printing symbolic error names
Starting with v5.5, Linux has a format specifier for printing error
pointers. We have had strerror in barebox before that, but lets wire it
into vsprintf with the same format specifier that Linux now uses.
This yields less verbose call sites and makes Linux drivers more portable
to barebox in future. This also has the potential to reduce code size as
the previously "inlined" strerror at callsites can now be replaced by
a single vsprintf.
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | lib/vsprintf.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 3e5f4db75a..3fccfa7a56 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -177,6 +177,17 @@ static char *string(char *buf, const char *end, const char *s, int field_width, return buf; } +static char *raw_pointer(char *buf, const char *end, const void *ptr, int field_width, + int precision, int flags) +{ + flags |= SMALL; + if (field_width == -1) { + field_width = 2*sizeof(void *); + flags |= ZEROPAD; + } + return number(buf, end, (unsigned long) ptr, 16, field_width, precision, flags); +} + #ifndef __PBL__ static char *symbol_string(char *buf, const char *end, const void *ptr, int field_width, int precision, int flags) @@ -214,6 +225,16 @@ char *ip4_addr_string(char *buf, const char *end, const u8 *addr, int field_widt return string(buf, end, ip4_addr, field_width, precision, flags); } +static +char *error_string(char *buf, const char *end, const u8 *errptr, int field_width, + int precision, int flags, const char *fmt) +{ + if (!IS_ERR(errptr)) + return raw_pointer(buf, end, errptr, field_width, precision, flags); + + return string(buf, end, strerrorp(errptr), field_width, precision, flags); +} + static noinline_for_stack char *uuid_string(char *buf, const char *end, const u8 *addr, int field_width, int precision, int flags, const char *fmt) @@ -345,24 +366,18 @@ static char *pointer(const char *fmt, char *buf, const char *end, const void *pt return ip4_addr_string(buf, end, ptr, field_width, precision, flags, fmt); } break; + case 'e': + return error_string(buf, end, ptr, field_width, precision, flags, fmt); } - flags |= SMALL; - if (field_width == -1) { - field_width = 2*sizeof(void *); - flags |= ZEROPAD; - } - return number(buf, end, (unsigned long) ptr, 16, field_width, precision, flags); + + return raw_pointer(buf, end, ptr, field_width, precision, flags); } + #else static char *pointer(const char *fmt, char *buf, const char *end, const void *ptr, int field_width, int precision, int flags) { - flags |= SMALL; - if (field_width == -1) { - field_width = 2*sizeof(void *); - flags |= ZEROPAD; - } - return number(buf, end, (unsigned long) ptr, 16, field_width, precision, flags); + return raw_pointer(buf, end, ptr, field_width, precision, flags); } #endif |