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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01EE8C433FE for ; Fri, 11 Nov 2022 14:50:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233602AbiKKOug (ORCPT ); Fri, 11 Nov 2022 09:50:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234362AbiKKOuU (ORCPT ); Fri, 11 Nov 2022 09:50:20 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 238AA532CE; Fri, 11 Nov 2022 06:50:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D2E7CB8262E; Fri, 11 Nov 2022 14:50:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2715C433C1; Fri, 11 Nov 2022 14:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668178217; bh=iCLjWMPbfoh16X7pYdvXNGmxZTqAzxVpz4NBBs8pJhs=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=o1B3isv3nOETepxAnGjwTi1UtBQLXiNIdvIaTRvA+NqqGwYzmtm7Kf4jw0reiB8uo NUZvtzNz0eVeWcpooIGWlstMbzi/0DETeBtpclSiu77iF96/GhicS9gWIn2FH8s82/ 0ZRUjWzeGzReWnEpbJrUFQoY8ocbsBV4u2yI5IXc2zufZw/cDu8pVg5qi3E4jxsgF7 QYpnUuO1tF1ptMI3qAze4kemGU9ztFZOZScBeQb/gCPIKwdKtvO7X4vtXHUclhklPM HdkEEQjkRPNnV5Om6UMXvNnpDHYgJx2iHkpzVdqr2C9hn6C60kRD0IAQYoED3hFDA2 siv5EOaT2V8Kg== Message-ID: Subject: Re: [PATCH -next] NFSD: Use struct_size() helpler in alloc_session() From: Jeff Layton To: Xiu Jianfeng , chuck.lever@oracle.com Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 11 Nov 2022 09:50:15 -0500 In-Reply-To: <20221111091835.151942-1-xiujianfeng@huawei.com> References: <20221111091835.151942-1-xiujianfeng@huawei.com> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2022-11-11 at 17:18 +0800, Xiu Jianfeng wrote: > Use struct_size() helper to simplify the code, no functional changes. >=20 > Signed-off-by: Xiu Jianfeng > --- > fs/nfsd/nfs4state.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) >=20 > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c > index 2ec981fd2985..97badca3135e 100644 > --- a/fs/nfsd/nfs4state.c > +++ b/fs/nfsd/nfs4state.c > @@ -1833,13 +1833,12 @@ static struct nfsd4_session *alloc_session(struct= nfsd4_channel_attrs *fattrs, > int numslots =3D fattrs->maxreqs; > int slotsize =3D slot_bytes(fattrs); > struct nfsd4_session *new; > - int mem, i; > + int i; > =20 > - BUILD_BUG_ON(NFSD_MAX_SLOTS_PER_SESSION * sizeof(struct nfsd4_slot *) > - + sizeof(struct nfsd4_session) > PAGE_SIZE); > - mem =3D numslots * sizeof(struct nfsd4_slot *); > + BUILD_BUG_ON(struct_size(new, se_slots, NFSD_MAX_SLOTS_PER_SESSION) > + > PAGE_SIZE); > =20 > - new =3D kzalloc(sizeof(*new) + mem, GFP_KERNEL); > + new =3D kzalloc(struct_size(new, se_slots, numslots), GFP_KERNEL); > if (!new) > return NULL; > /* allocate each struct nfsd4_slot and data cache in one piece */ Reviewed-by: Jeff Layton