diff options
author | Arvind Sankar <nivedita@alum.mit.edu> | 2020-05-18 15:07:04 -0400 |
---|---|---|
committer | Ard Biesheuvel <ardb@kernel.org> | 2020-05-19 10:31:50 +0200 |
commit | dec6119952eab7257624de5bd116a9e301ead5b7 (patch) | |
tree | f8081d629f3b7a724d662e53b8d21cf8f0d05bc5 /drivers/firmware | |
parent | 3fbcf75bb41a0ff02189f6e873ba4c5d7c54c6a9 (diff) | |
download | linux-dec6119952eab7257624de5bd116a9e301ead5b7.tar.bz2 |
efi/printf: Factor out integer argument retrieval
Factor out the code to get the correct type of numeric argument into a
helper function.
Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Link: https://lore.kernel.org/r/20200518190716.751506-13-nivedita@alum.mit.edu
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Diffstat (limited to 'drivers/firmware')
-rw-r--r-- | drivers/firmware/efi/libstub/vsprintf.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/drivers/firmware/efi/libstub/vsprintf.c b/drivers/firmware/efi/libstub/vsprintf.c index 0e6f2c1158fd..27685c726c64 100644 --- a/drivers/firmware/efi/libstub/vsprintf.c +++ b/drivers/firmware/efi/libstub/vsprintf.c @@ -244,6 +244,38 @@ int get_int(const char **fmt, va_list *ap) return 0; } +static +unsigned long long get_number(int sign, int qualifier, va_list *ap) +{ + if (sign) { + switch (qualifier) { + case 'L': + return va_arg(*ap, long long); + case 'l': + return va_arg(*ap, long); + case 'h': + return (short)va_arg(*ap, int); + case 'H': + return (signed char)va_arg(*ap, int); + default: + return va_arg(*ap, int); + }; + } else { + switch (qualifier) { + case 'L': + return va_arg(*ap, unsigned long long); + case 'l': + return va_arg(*ap, unsigned long); + case 'h': + return (unsigned short)va_arg(*ap, int); + case 'H': + return (unsigned char)va_arg(*ap, int); + default: + return va_arg(*ap, unsigned int); + } + } +} + int vsprintf(char *buf, const char *fmt, va_list ap) { int len; @@ -370,40 +402,8 @@ int vsprintf(char *buf, const char *fmt, va_list ap) } if (*fmt == 'p') { num = (unsigned long)va_arg(args, void *); - } else if (flags & SIGN) { - switch (qualifier) { - case 'L': - num = va_arg(args, long long); - break; - case 'l': - num = va_arg(args, long); - break; - case 'h': - num = (short)va_arg(args, int); - break; - case 'H': - num = (signed char)va_arg(args, int); - break; - default: - num = va_arg(args, int); - } } else { - switch (qualifier) { - case 'L': - num = va_arg(args, unsigned long long); - break; - case 'l': - num = va_arg(args, unsigned long); - break; - case 'h': - num = (unsigned short)va_arg(args, int); - break; - case 'H': - num = (unsigned char)va_arg(args, int); - break; - default: - num = va_arg(args, unsigned int); - } + num = get_number(flags & SIGN, qualifier, &args); } str = number(str, num, base, field_width, precision, flags); } |