summaryrefslogtreecommitdiff
path: root/fs/afs/dir.c
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /fs/afs/dir.c
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlinux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz
linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.zip
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to avoid scalar types (which need careful case-by-case checking), and instead replace kmalloc-family calls that allocate struct or union object instances: Single allocations: kmalloc(sizeof(TYPE), ...) are replaced with: kmalloc_obj(TYPE, ...) Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...) are replaced with: kmalloc_objs(TYPE, COUNT, ...) Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...) are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...) (where TYPE may also be *VAR) The resulting allocations no longer return "void *", instead returning "TYPE *". Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'fs/afs/dir.c')
-rw-r--r--fs/afs/dir.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index f4e9e12373ac..6f7380f25365 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -785,7 +785,7 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry)
_enter("{%lu},%p{%pd},", dir->i_ino, dentry, dentry);
- cookie = kzalloc(sizeof(struct afs_lookup_cookie), GFP_KERNEL);
+ cookie = kzalloc_obj(struct afs_lookup_cookie, GFP_KERNEL);
if (!cookie)
return ERR_PTR(-ENOMEM);
@@ -834,9 +834,8 @@ static struct inode *afs_do_lookup(struct inode *dir, struct dentry *dentry)
/* Need space for examining all the selected files */
if (op->nr_files > 2) {
- op->more_files = kvcalloc(op->nr_files - 2,
- sizeof(struct afs_vnode_param),
- GFP_KERNEL);
+ op->more_files = kvzalloc_objs(struct afs_vnode_param,
+ op->nr_files - 2, GFP_KERNEL);
if (!op->more_files) {
afs_op_nomem(op);
goto out_op;
@@ -2095,7 +2094,7 @@ static int afs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
goto error;
ret = -ENOMEM;
- op->more_files = kvcalloc(2, sizeof(struct afs_vnode_param), GFP_KERNEL);
+ op->more_files = kvzalloc_objs(struct afs_vnode_param, 2, GFP_KERNEL);
if (!op->more_files)
goto error;