Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/vsprintf.c: move sizeof(struct printf_spec) next to its definition

At the time of commit d048419311ff ("lib/vsprintf.c: expand field_width
to 24 bits"), there was no compiletime_assert/BUILD_BUG/.... variant
that could be used outside function scope. Now we have static_assert(),
so move the assertion next to the definition instead of hiding it in
some arbitrary function.

Also add the appropriate #include to avoid relying on build_bug.h being
pulled in via some arbitrary chain of includes.

Link: http://lkml.kernel.org/r/20190208203015.29702-2-linux@rasmusvillemoes.dk
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Kees Cook <keescook@chromium.org>
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Rasmus Villemoes and committed by
Linus Torvalds
ef27ac18 6bab69c6

+3 -2
+3 -2
lib/vsprintf.c
··· 17 17 */ 18 18 19 19 #include <stdarg.h> 20 + #include <linux/build_bug.h> 20 21 #include <linux/clk.h> 21 22 #include <linux/clk-provider.h> 22 23 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */ ··· 406 405 unsigned int base:8; /* number base, 8, 10 or 16 only */ 407 406 signed int precision:16; /* # of digits/chars */ 408 407 } __packed; 408 + static_assert(sizeof(struct printf_spec) == 8); 409 + 409 410 #define FIELD_WIDTH_MAX ((1 << 23) - 1) 410 411 #define PRECISION_MAX ((1 << 15) - 1) 411 412 ··· 424 421 bool is_zero = num == 0LL; 425 422 int field_width = spec.field_width; 426 423 int precision = spec.precision; 427 - 428 - BUILD_BUG_ON(sizeof(struct printf_spec) != 8); 429 424 430 425 /* locase = 0 or 0x20. ORing digits or letters with 'locase' 431 426 * produces same digits or (maybe lowercased) letters */