[PATCH 2/4] vsprintf: add %pe format specifier for printing symbolic error names

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux