Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Zhengyuan Liu and committed by
David Howells
ee102584 45218193

+4 -8
+1 -2
fs/afs/dir.c
··· 242 242 if (nr_inline > (PAGE_SIZE - sizeof(*req)) / sizeof(struct page *)) 243 243 nr_inline = 0; 244 244 245 - req = kzalloc(sizeof(*req) + sizeof(struct page *) * nr_inline, 246 - GFP_KERNEL); 245 + req = kzalloc(struct_size(req, array, nr_inline), GFP_KERNEL); 247 246 if (!req) 248 247 return ERR_PTR(-ENOMEM); 249 248
+2 -4
fs/afs/file.c
··· 314 314 /* fall through */ 315 315 default: 316 316 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); 319 318 if (!req) 320 319 goto enomem; 321 320 ··· 464 465 n++; 465 466 } 466 467 467 - req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *) * n, 468 - GFP_NOFS); 468 + req = kzalloc(struct_size(req, array, n), GFP_NOFS); 469 469 if (!req) 470 470 return -ENOMEM; 471 471
+1 -2
fs/afs/write.c
··· 48 48 return 0; 49 49 } 50 50 51 - req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *), 52 - GFP_KERNEL); 51 + req = kzalloc(struct_size(req, array, 1), GFP_KERNEL); 53 52 if (!req) 54 53 return -ENOMEM; 55 54