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>
Thu, 10 Feb 2022 02:59:35 +0000 (18:59 -0800)
commit1c1d836b96ba1bd773881c7f4784c77b94d58e25
tree42d646d71d90afdaf642138d6ec9bba509d690aa
parent6312fc63aee9d2fef2f9c4d42e57e5b46828f0dc
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