Re: [PATCH] mtd: rawnand: rockchip: Use struct_size()

From: Kees Cook
Date: Mon Oct 09 2023 - 16:00:12 EST


On Sun, Oct 01, 2023 at 09:44:04AM +0200, Christophe JAILLET wrote:
> Use struct_size() instead of hand writing it.
> This is less verbose and more robust.
>
> While at it, prepare for the coming implementation by GCC and Clang of the
> __counted_by attribute. Flexible array members annotated with __counted_by
> can have their accesses bounds-checked at run-time checking via
> CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for
> strcpy/memcpy-family functions).
>
> Also remove a useless comment about the position of a flex-array in a
> structure.
>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>

It seems the consensus is to keep the struct_size() changes together
with the __counted_by annotation, so yes, this looks correct to me:

Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>

--
Kees Cook