summaryrefslogtreecommitdiff
path: root/fs/configfs
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/configfs
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
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/configfs')
-rw-r--r--fs/configfs/dir.c4
-rw-r--r--fs/configfs/file.c2
-rw-r--r--fs/configfs/inode.c2
3 files changed, 4 insertions, 4 deletions
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index ba95f636a5ab..f437b1ab3b68 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -159,7 +159,7 @@ static struct configfs_fragment *new_fragment(void)
{
struct configfs_fragment *p;
- p = kmalloc(sizeof(struct configfs_fragment), GFP_KERNEL);
+ p = kmalloc_obj(struct configfs_fragment, GFP_KERNEL);
if (p) {
atomic_set(&p->frag_count, 1);
init_rwsem(&p->frag_sem);
@@ -1847,7 +1847,7 @@ configfs_register_default_group(struct config_group *parent_group,
int ret;
struct config_group *group;
- group = kzalloc(sizeof(*group), GFP_KERNEL);
+ group = kzalloc_obj(*group, GFP_KERNEL);
if (!group)
return ERR_PTR(-ENOMEM);
config_group_init_type_name(group, name, item_type);
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index affe4742bbb5..a83d1981e96f 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -296,7 +296,7 @@ static int __configfs_open_file(struct inode *inode, struct file *file, int type
int error;
error = -ENOMEM;
- buffer = kzalloc(sizeof(struct configfs_buffer), GFP_KERNEL);
+ buffer = kzalloc_obj(struct configfs_buffer, GFP_KERNEL);
if (!buffer)
goto out;
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c
index bcda3372e141..e7d8500fee7d 100644
--- a/fs/configfs/inode.c
+++ b/fs/configfs/inode.c
@@ -47,7 +47,7 @@ int configfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
sd_iattr = sd->s_iattr;
if (!sd_iattr) {
/* setting attributes for the first time, allocate now */
- sd_iattr = kzalloc(sizeof(struct iattr), GFP_KERNEL);
+ sd_iattr = kzalloc_obj(struct iattr, GFP_KERNEL);
if (!sd_iattr)
return -ENOMEM;
/* assign default attributes */