From: Arvind Sankar Date: Mon, 18 May 2020 19:07:04 +0000 (-0400) Subject: efi/printf: Factor out integer argument retrieval X-Git-Tag: v5.15~3781^2~1^2~17 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dec6119952eab7257624de5bd116a9e301ead5b7;p=platform%2Fkernel%2Flinux-starfive.git 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 Link: https://lore.kernel.org/r/20200518190716.751506-13-nivedita@alum.mit.edu Signed-off-by: Ard Biesheuvel --- diff --git a/drivers/firmware/efi/libstub/vsprintf.c b/drivers/firmware/efi/libstub/vsprintf.c index 0e6f2c1..27685c7 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); }