OSDN Git Service

overflow: Provide constant expression struct_size
authorKees Cook <keescook@chromium.org>
Thu, 10 Feb 2022 00:40:41 +0000 (16:40 -0800)
committerKees Cook <keescook@chromium.org>
Wed, 16 Feb 2022 22:30:37 +0000 (14:30 -0800)
commit230f6fa2c1db6a3f3e668cfe95995ac8e6eee212
tree0efbee5d1df73b95483adf495bb6e2232342fc7d
parente1be43d9b5d0d1310dbd90185a8e5c7145dde40f
overflow: Provide constant expression struct_size

There have been cases where struct_size() (or flex_array_size()) needs
to be calculated for an initializer, which requires it be a constant
expression. This is possible when the "count" argument is a constant
expression, so provide this ability for the helpers.

Cc: Gustavo A. R. Silva <gustavoars@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Tested-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/lkml/20220210010407.GA701603@embeddedor
include/linux/overflow.h
lib/test_overflow.c