diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /fs/nilfs2 | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (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/nilfs2')
| -rw-r--r-- | fs/nilfs2/alloc.c | 2 | ||||
| -rw-r--r-- | fs/nilfs2/recovery.c | 4 | ||||
| -rw-r--r-- | fs/nilfs2/segment.c | 2 | ||||
| -rw-r--r-- | fs/nilfs2/super.c | 2 | ||||
| -rw-r--r-- | fs/nilfs2/the_nilfs.c | 4 |
5 files changed, 7 insertions, 7 deletions
diff --git a/fs/nilfs2/alloc.c b/fs/nilfs2/alloc.c index 6b506995818d..e7eebb04f9a4 100644 --- a/fs/nilfs2/alloc.c +++ b/fs/nilfs2/alloc.c @@ -54,7 +54,7 @@ int nilfs_palloc_init_blockgroup(struct inode *inode, unsigned int entry_size) { struct nilfs_mdt_info *mi = NILFS_MDT(inode); - mi->mi_bgl = kmalloc(sizeof(*mi->mi_bgl), GFP_NOFS); + mi->mi_bgl = kmalloc_obj(*mi->mi_bgl, GFP_NOFS); if (!mi->mi_bgl) return -ENOMEM; diff --git a/fs/nilfs2/recovery.c b/fs/nilfs2/recovery.c index a9c61d0492cb..4d5a6aa5214c 100644 --- a/fs/nilfs2/recovery.c +++ b/fs/nilfs2/recovery.c @@ -370,7 +370,7 @@ static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr, if (unlikely(!binfo)) goto out; - rb = kmalloc(sizeof(*rb), GFP_NOFS); + rb = kmalloc_obj(*rb, GFP_NOFS); if (unlikely(!rb)) { err = -ENOMEM; goto out; @@ -414,7 +414,7 @@ struct nilfs_segment_entry { static int nilfs_segment_list_add(struct list_head *head, __u64 segnum) { - struct nilfs_segment_entry *ent = kmalloc(sizeof(*ent), GFP_NOFS); + struct nilfs_segment_entry *ent = kmalloc_obj(*ent, GFP_NOFS); if (unlikely(!ent)) return -ENOMEM; diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index deee16bc9d4e..21c5539c7e84 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -2701,7 +2701,7 @@ static struct nilfs_sc_info *nilfs_segctor_new(struct super_block *sb, struct the_nilfs *nilfs = sb->s_fs_info; struct nilfs_sc_info *sci; - sci = kzalloc(sizeof(*sci), GFP_KERNEL); + sci = kzalloc_obj(*sci, GFP_KERNEL); if (!sci) return NULL; diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c index badc2cbc895e..55fac3f83232 100644 --- a/fs/nilfs2/super.c +++ b/fs/nilfs2/super.c @@ -1292,7 +1292,7 @@ static int nilfs_init_fs_context(struct fs_context *fc) { struct nilfs_fs_context *ctx; - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + ctx = kzalloc_obj(*ctx, GFP_KERNEL); if (!ctx) return -ENOMEM; diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index d0bcf744c553..f481532ea8e9 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c @@ -56,7 +56,7 @@ struct the_nilfs *alloc_nilfs(struct super_block *sb) { struct the_nilfs *nilfs; - nilfs = kzalloc(sizeof(*nilfs), GFP_KERNEL); + nilfs = kzalloc_obj(*nilfs, GFP_KERNEL); if (!nilfs) return NULL; @@ -877,7 +877,7 @@ nilfs_find_or_create_root(struct the_nilfs *nilfs, __u64 cno) if (root) return root; - new = kzalloc(sizeof(*root), GFP_KERNEL); + new = kzalloc_obj(*root, GFP_KERNEL); if (!new) return NULL; |
