Skip to content

Commit 85a0d0c

Browse files
Xiu JianfengChuck Lever
authored andcommitted
NFSD: Use struct_size() helper in alloc_session()
Use struct_size() helper to simplify the code, no functional changes. Signed-off-by: Xiu Jianfeng <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 01d53a8 commit 85a0d0c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

fs/nfsd/nfs4state.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,13 +1833,12 @@ static struct nfsd4_session *alloc_session(struct nfsd4_channel_attrs *fattrs,
18331833
int numslots = fattrs->maxreqs;
18341834
int slotsize = slot_bytes(fattrs);
18351835
struct nfsd4_session *new;
1836-
int mem, i;
1836+
int i;
18371837

1838-
BUILD_BUG_ON(NFSD_MAX_SLOTS_PER_SESSION * sizeof(struct nfsd4_slot *)
1839-
+ sizeof(struct nfsd4_session) > PAGE_SIZE);
1840-
mem = numslots * sizeof(struct nfsd4_slot *);
1838+
BUILD_BUG_ON(struct_size(new, se_slots, NFSD_MAX_SLOTS_PER_SESSION)
1839+
> PAGE_SIZE);
18411840

1842-
new = kzalloc(sizeof(*new) + mem, GFP_KERNEL);
1841+
new = kzalloc(struct_size(new, se_slots, numslots), GFP_KERNEL);
18431842
if (!new)
18441843
return NULL;
18451844
/* allocate each struct nfsd4_slot and data cache in one piece */

0 commit comments

Comments
 (0)