public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] printf: Emit "SUCCESS" if NULL is passed for %pe
@ 2022-09-30 11:10 Uwe Kleine-König
  2022-09-30 12:14 ` Petr Mladek
  2022-09-30 13:41 ` Andy Shevchenko
  0 siblings, 2 replies; 8+ messages in thread
From: Uwe Kleine-König @ 2022-09-30 11:10 UTC (permalink / raw)
  To: Petr Mladek, Steven Rostedt, Sergey Senozhatsky
  Cc: Andy Shevchenko, Rasmus Villemoes, linux-kernel, kernel

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@pengutronix.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


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

end of thread, other threads:[~2022-10-03 13:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-30 11:10 [PATCH] printf: Emit "SUCCESS" if NULL is passed for %pe Uwe Kleine-König
2022-09-30 12:14 ` Petr Mladek
2022-09-30 13:24   ` Uwe Kleine-König
2022-09-30 13:42     ` Andy Shevchenko
2022-09-30 13:48       ` Uwe Kleine-König
2022-09-30 13:41 ` Andy Shevchenko
2022-09-30 14:05   ` Uwe Kleine-König
2022-10-03 13:26     ` Petr Mladek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox