fs/afs: use struct_size() in kzalloc()
authorZhengyuan Liu <liuzhengyuan@kylinos.cn>
Thu, 20 Jun 2019 17:12:17 +0000 (18:12 +0100)
committerDavid Howells <dhowells@redhat.com>
Thu, 20 Jun 2019 17:12:17 +0000 (18:12 +0100)
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>
fs/afs/dir.c
fs/afs/file.c
fs/afs/write.c

index e8c58c94eb615abffc0c2a0321de6866416e08ae..5dff607a08f9909e3e64f2155d4230081ea5404f 100644 (file)
@@ -242,8 +242,7 @@ retry:
        if (nr_inline > (PAGE_SIZE - sizeof(*req)) / sizeof(struct page *))
                nr_inline = 0;
 
-       req = kzalloc(sizeof(*req) + sizeof(struct page *) * nr_inline,
-                     GFP_KERNEL);
+       req = kzalloc(struct_size(req, array, nr_inline), GFP_KERNEL);
        if (!req)
                return ERR_PTR(-ENOMEM);
 
index 11e69c5fb7abb5554605fbb4974146d9f375af75..67cd782a1c64f8d867ef446545e587d2c0a0da60 100644 (file)
@@ -314,8 +314,7 @@ int afs_page_filler(void *data, struct page *page)
                /* fall through */
        default:
        go_on:
-               req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *),
-                             GFP_KERNEL);
+               req = kzalloc(struct_size(req, array, 1), GFP_KERNEL);
                if (!req)
                        goto enomem;
 
@@ -465,8 +464,7 @@ static int afs_readpages_one(struct file *file, struct address_space *mapping,
                n++;
        }
 
-       req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *) * n,
-                     GFP_NOFS);
+       req = kzalloc(struct_size(req, array, n), GFP_NOFS);
        if (!req)
                return -ENOMEM;
 
index 8bcab95f11273aeeb94e0347b9696960e0f1138a..9cea9c40a4efc19d251f867ad7e0db4b5d8d8f2f 100644 (file)
@@ -48,8 +48,7 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key,
                return 0;
        }
 
-       req = kzalloc(sizeof(struct afs_read) + sizeof(struct page *),
-                     GFP_KERNEL);
+       req = kzalloc(struct_size(req, array, 1), GFP_KERNEL);
        if (!req)
                return -ENOMEM;