]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
NFSD: Use struct_size() helper in alloc_session()
authorXiu Jianfeng <xiujianfeng@huawei.com>
Fri, 11 Nov 2022 09:18:35 +0000 (17:18 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:19:23 +0000 (16:19 +0200)
[ Upstream commit 85a0d0c9a58002ef7d1bf5e3ea630f4fbd42a4f0 ]

Use struct_size() helper to simplify the code, no functional changes.

Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs4state.c

index 39b315e3471f56986cf1d7d1f8557365a09f7e3f..524865c7211ef8f61f4330acfb16e413b7168fa3 100644 (file)
@@ -1833,13 +1833,12 @@ static struct nfsd4_session *alloc_session(struct nfsd4_channel_attrs *fattrs,
        int numslots = fattrs->maxreqs;
        int slotsize = slot_bytes(fattrs);
        struct nfsd4_session *new;
-       int mem, i;
+       int i;
 
-       BUILD_BUG_ON(NFSD_MAX_SLOTS_PER_SESSION * sizeof(struct nfsd4_slot *)
-                       + sizeof(struct nfsd4_session) > PAGE_SIZE);
-       mem = numslots * sizeof(struct nfsd4_slot *);
+       BUILD_BUG_ON(struct_size(new, se_slots, NFSD_MAX_SLOTS_PER_SESSION)
+                    > PAGE_SIZE);
 
-       new = kzalloc(sizeof(*new) + mem, GFP_KERNEL);
+       new = kzalloc(struct_size(new, se_slots, numslots), GFP_KERNEL);
        if (!new)
                return NULL;
        /* allocate each struct nfsd4_slot and data cache in one piece */