Skip to content

Commit 7c30fd7

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/printf: Merge 'p' with the integer formats
Treat 'p' as a hexadecimal integer with precision equal to the number of digits in void *. Signed-off-by: Arvind Sankar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 77e48db commit 7c30fd7

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

drivers/firmware/efi/libstub/vsprintf.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,6 @@ int vsprintf(char *buf, const char *fmt, va_list args)
297297
}
298298
}
299299

300-
/* default base */
301-
base = 10;
302-
303300
switch (*fmt) {
304301
case 'c':
305302
if (!(flags & LEFT))
@@ -323,21 +320,15 @@ int vsprintf(char *buf, const char *fmt, va_list args)
323320
*str++ = ' ';
324321
continue;
325322

326-
case 'p':
327-
if (field_width == -1) {
328-
field_width = 2 * sizeof(void *);
329-
flags |= ZEROPAD;
330-
}
331-
str = number(str,
332-
(unsigned long)va_arg(args, void *), 16,
333-
field_width, precision, flags);
334-
continue;
335-
336323
/* integer number formats - set up the flags and "break" */
337324
case 'o':
338325
base = 8;
339326
break;
340327

328+
case 'p':
329+
if (precision < 0)
330+
precision = 2 * sizeof(void *);
331+
fallthrough;
341332
case 'x':
342333
flags |= SMALL;
343334
fallthrough;
@@ -350,6 +341,7 @@ int vsprintf(char *buf, const char *fmt, va_list args)
350341
flags |= SIGN;
351342
fallthrough;
352343
case 'u':
344+
base = 10;
353345
break;
354346

355347
default:
@@ -360,7 +352,9 @@ int vsprintf(char *buf, const char *fmt, va_list args)
360352
--fmt;
361353
continue;
362354
}
363-
if (flags & SIGN) {
355+
if (*fmt == 'p') {
356+
num = (unsigned long)va_arg(args, void *);
357+
} else if (flags & SIGN) {
364358
switch (qualifier) {
365359
case 'L':
366360
num = va_arg(args, long long);

0 commit comments

Comments
 (0)