lib: Allow using 0x when a decimal value is requested

U-Boot mostly uses hex for value input, largely because addresses are much
easier to understand in hex.

But in some cases a decimal value is requested, such as where the value is
small or hex does not make sense in the context. In these cases it is
sometimes useful to be able to provide a hex value in any case, if only to
resolve any ambiguity.

Add this functionality, for increased flexibility.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/lib/strto.c b/lib/strto.c
index b056b20..7bba1e3 100644
--- a/lib/strto.c
+++ b/lib/strto.c
@@ -14,19 +14,25 @@
 #include <linux/ctype.h>
 
 /* from lib/kstrtox.c */
-static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
+static const char *_parse_integer_fixup_radix(const char *s, uint *basep)
 {
-	if (*base == 0) {
-		if (s[0] == '0') {
-			if (tolower(s[1]) == 'x')
-				*base = 16;
-			else
-				*base = 8;
-		} else
-			*base = 10;
+	/* Look for a 0x prefix */
+	if (s[0] == '0') {
+		int ch = tolower(s[1]);
+
+		if (ch == 'x') {
+			*basep = 16;
+			s += 2;
+		} else if (!*basep) {
+			/* Only select octal if we don't have a base */
+			*basep = 8;
+		}
 	}
-	if (*base == 16 && s[0] == '0' && tolower(s[1]) == 'x')
-		s += 2;
+
+	/* Use decimal by default */
+	if (!*basep)
+		*basep = 10;
+
 	return s;
 }