From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 060DAC2BBD4 for ; Wed, 16 Dec 2020 04:44:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C120C2313F for ; Wed, 16 Dec 2020 04:44:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725871AbgLPEoQ (ORCPT ); Tue, 15 Dec 2020 23:44:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:49698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725868AbgLPEoP (ORCPT ); Tue, 15 Dec 2020 23:44:15 -0500 Date: Tue, 15 Dec 2020 20:43:04 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608093784; bh=6oWq1aGZWE7QajV7AdoruVbd3lEaszTyxMzrJs9wsFs=; h=From:To:Subject:In-Reply-To:From; b=BBMhxMLEEBiokR0FX/ZImDMe9OxPdz71a4Vo0ggQJjZ73ZKw0FPnGXxFG7ZZuDJqj b5JuK+NypC0D/NRC/D9d6p2caD6gt62IzNpoM0n5NLrOm+1f53VzY8fdJmaVN3/fuo 6Tkcsc9oRYQqnWjLth6DZPyjz8BBq4WVtuOjZOkI= From: Andrew Morton To: akpm@linux-foundation.org, gustavoars@kernel.org, linux-mm@kvack.org, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 14/95] lib/stackdepot.c: replace one-element array with flexible-array member Message-ID: <20201216044304.h98-SpUk7%akpm@linux-foundation.org> In-Reply-To: <20201215204156.f05ec694b907845bcfab5c44@linux-foundation.org> User-Agent: s-nail v14.8.16 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org =46rom: "Gustavo A. R. Silva" Subject: lib/stackdepot.c: replace one-element array with flexible-array me= mber Patch series "] lib/stackdepot.c: Replace one-element array with flexible-a= rray member". This series aims to replace a one-element array with a flexible-array member. Also, make use of the struct_size(), flexible_array_size() and array_size() helpers. This patch (of 3): There is a regular need in the kernel to provide a way to declare having a dynamically sized set of trailing elements in a structure. Kernel code should always use =E2=80=9Cflexible array members=E2=80=9D[1] for these cas= es. The older style of one-element or zero-length arrays should no longer be used[2]. Refactor the code according to the use of a flexible-array member in struct stack_record, instead of a one-element array, and use the struct_size() helper to calculate the size for the allocation. [1] https://en.wikipedia.org/wiki/Flexible_array_member [2] https://www.kernel.org/doc/html/v5.9-rc1/process/deprecated.html#zero-l= ength-and-one-element-arrays Link: https://lkml.kernel.org/r/cover.1601565471.git.gustavoars@kernel.org Link: https://lore.kernel.org/lkml/5f75876b.x9zdN10esiC0qLHV%25lkp@intel.co= m/ Link: https://lkml.kernel.org/r/2f1e6a17aaa891ad9c58817cf0a10b8ab8894f59.16= 01565471.git.gustavoars@kernel.org Signed-off-by: Gustavo A. R. Silva Signed-off-by: Andrew Morton --- lib/stackdepot.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) --- a/lib/stackdepot.c~lib-stackdepotc-replace-one-element-array-with-flexi= ble-array-member +++ a/lib/stackdepot.c @@ -62,7 +62,7 @@ struct stack_record { u32 hash; /* Hash in the hastable */ u32 size; /* Number of frames in the stack */ union handle_parts handle; - unsigned long entries[1]; /* Variable-sized array of entries. */ + unsigned long entries[]; /* Variable-sized array of entries. */ }; =20 static void *stack_slabs[STACK_ALLOC_MAX_SLABS]; @@ -104,9 +104,8 @@ static bool init_stack_slab(void **preal static struct stack_record *depot_alloc_stack(unsigned long *entries, int = size, u32 hash, void **prealloc, gfp_t alloc_flags) { - int required_size =3D offsetof(struct stack_record, entries) + - sizeof(unsigned long) * size; struct stack_record *stack; + size_t required_size =3D struct_size(stack, entries, size); =20 required_size =3D ALIGN(required_size, 1 << STACK_ALLOC_ALIGN); =20 _