mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: "Ahmad Fatoum" <a.fatoum@pengutronix.de>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: [PATCH 2/4] vsprintf: add %pe format specifier for printing symbolic error names
Date: Mon, 28 Sep 2020 17:34:29 +0200	[thread overview]
Message-ID: <20200928153431.1095-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20200928153431.1095-1-a.fatoum@pengutronix.de>

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>
---
 lib/vsprintf.c | 39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 3e5f4db75ac8..3fccfa7a56ba 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
 
-- 
2.28.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-09-28 15:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-28 15:34 [PATCH 1/4] vsprintf: constify pointers where appropriate Ahmad Fatoum
2020-09-28 15:34 ` Ahmad Fatoum [this message]
2020-09-28 15:34 ` [PATCH 3/4] vsprintf: retire strerrorp in favor of %pe Ahmad Fatoum
2020-09-28 15:34 ` [PATCH 4/4] treewide: replace strerror(-PTR_ERR(errno)) with %pe format specifier Ahmad Fatoum
2020-09-29  6:42 ` [PATCH 1/4] vsprintf: constify pointers where appropriate Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200928153431.1095-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox