From: Thorsten Blum Date: Thu, 30 Oct 2025 16:32:17 +0000 (+0100) Subject: crypto: deflate - Use struct_size to improve deflate_alloc_stream X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b6410c1e50164da0542b671fc14caf4cff1c4819;p=thirdparty%2Flinux.git crypto: deflate - Use struct_size to improve deflate_alloc_stream Use struct_size(), which provides additional compile-time checks for structures with flexible array members (e.g., __must_be_array()), to calculate the allocation size for a new 'deflate_stream'. Signed-off-by: Thorsten Blum Signed-off-by: Herbert Xu --- diff --git a/crypto/deflate.c b/crypto/deflate.c index 21404515dc77e..a3e1fff55661b 100644 --- a/crypto/deflate.c +++ b/crypto/deflate.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -39,7 +40,7 @@ static void *deflate_alloc_stream(void) DEFLATE_DEF_MEMLEVEL)); struct deflate_stream *ctx; - ctx = kvmalloc(sizeof(*ctx) + size, GFP_KERNEL); + ctx = kvmalloc(struct_size(ctx, workspace, size), GFP_KERNEL); if (!ctx) return ERR_PTR(-ENOMEM);