[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220930111050.1296018-1-u.kleine-koenig@pengutronix.de>
Date: Fri, 30 Sep 2022 13:10:50 +0200
From: Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>
To: Petr Mladek <pmladek@...e.com>,
Steven Rostedt <rostedt@...dmis.org>,
Sergey Senozhatsky <senozhatsky@...omium.org>
Cc: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
linux-kernel@...r.kernel.org, kernel@...gutronix.de
Subject: [PATCH] printf: Emit "SUCCESS" if NULL is passed for %pe
For code that emits a string representing a usual return value it's
convenient to have a 0 result in a string representation of success
instead of "00000000".
A usecase is tracing where the return value of a callback is emitted,
see
https://lore.kernel.org/linux-pwm/20220916151506.298488-2-u.kleine-koenig@pengutronix.de
for an example.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
---
lib/errname.c | 1 +
lib/vsprintf.c | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/errname.c b/lib/errname.c
index 05cbf731545f..2fd430f25059 100644
--- a/lib/errname.c
+++ b/lib/errname.c
@@ -15,6 +15,7 @@
*/
#define E(err) [err + BUILD_BUG_ON_ZERO(err <= 0 || err > 300)] = "-" #err
static const char *names_0[] = {
+ [0] = "SUCCESS",
E(E2BIG),
E(EACCES),
E(EADDRINUSE),
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3c1853a9d1c0..2a27218bab48 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2448,7 +2448,7 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
return pointer_string(buf, end, ptr, spec);
case 'e':
/* %pe with a non-ERR_PTR gets treated as plain %p */
- if (!IS_ERR(ptr))
+ if (!IS_ERR_OR_NULL(ptr))
return default_pointer(buf, end, ptr, spec);
return err_ptr(buf, end, ptr, spec);
case 'u':
--
2.30.2
Powered by blists - more mailing lists