Skip to content

Commit ee10258

Browse files
Zhengyuan Liudhowells
authored andcommitted
fs/afs: use struct_size() in kzalloc()
As Gustavo said in other patches doing the same replace, we can now use the new struct_size() helper to avoid leaving these open-coded and prone to type mistake. Signed-off-by: Zhengyuan Liu <liuzhengyuan@kylinos.cn> Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 4521819 commit ee10258

3 files changed

Lines changed: 4 additions & 8 deletions

File tree

‎fs/afs/dir.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key)
242242
if (nr_inline > (PAGE_SIZE - sizeof(*req)) / sizeof(struct page *))
243243
nr_inline = 0;
244244

245-
req = kzalloc(sizeof(*req) + sizeof(struct page *) * nr_inline,
246-
GFP_KERNEL);
245+
req = kzalloc(struct_size(req, array, nr_inline), GFP_KERNEL);
247246
if (!req)
248247
return ERR_PTR(-ENOMEM);
249248

‎fs/afs/file.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ int afs_page_filler(void *data, struct page *page)
314314
/* fall through */
315315
default:
316316
go_on:
317-
req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *),
318-
GFP_KERNEL);
317+
req = kzalloc(struct_size(req, array, 1), GFP_KERNEL);
319318
if (!req)
320319
goto enomem;
321320

@@ -465,8 +464,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
465464
n++;
466465
}
467466

468-
req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *) * n,
469-
GFP_NOFS);
467+
req = kzalloc(struct_size(req, array, n), GFP_NOFS);
470468
if (!req)
471469
return -ENOMEM;
472470

‎fs/afs/write.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key,
4848
return 0;
4949
}
5050

51-
req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *),
52-
GFP_KERNEL);
51+
req = kzalloc(struct_size(req, array, 1), GFP_KERNEL);
5352
if (!req)
5453
return -ENOMEM;
5554

0 commit comments

Comments
 (0)