summaryrefslogtreecommitdiff
path: root/fs/ext2
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/ext2
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/ext2')
-rw-r--r--fs/ext2/balloc.c2
-rw-r--r--fs/ext2/super.c11
2 files changed, 6 insertions, 7 deletions
diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index b8cfab8f98b9..2bac6dcb1792 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -419,7 +419,7 @@ void ext2_init_block_alloc_info(struct inode *inode)
struct ext2_block_alloc_info *block_i;
struct super_block *sb = inode->i_sb;
- block_i = kmalloc(sizeof(*block_i), GFP_KERNEL);
+ block_i = kmalloc_obj(*block_i, GFP_KERNEL);
if (block_i) {
struct ext2_reserve_window_node *rsv = &block_i->rsv_window_node;
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 121e634c792a..9bb4c63f5628 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -893,12 +893,12 @@ static int ext2_fill_super(struct super_block *sb, struct fs_context *fc)
__le32 features;
int err;
- sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
+ sbi = kzalloc_obj(*sbi, GFP_KERNEL);
if (!sbi)
return -ENOMEM;
sbi->s_blockgroup_lock =
- kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
+ kzalloc_obj(struct blockgroup_lock, GFP_KERNEL);
if (!sbi->s_blockgroup_lock) {
kfree(sbi);
return -ENOMEM;
@@ -1122,9 +1122,8 @@ static int ext2_fill_super(struct super_block *sb, struct fs_context *fc)
}
db_count = (sbi->s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
EXT2_DESC_PER_BLOCK(sb);
- sbi->s_group_desc = kvmalloc_array(db_count,
- sizeof(struct buffer_head *),
- GFP_KERNEL);
+ sbi->s_group_desc = kvmalloc_objs(struct buffer_head *, db_count,
+ GFP_KERNEL);
if (sbi->s_group_desc == NULL) {
ret = -ENOMEM;
ext2_msg(sb, KERN_ERR, "error: not enough memory");
@@ -1670,7 +1669,7 @@ static int ext2_init_fs_context(struct fs_context *fc)
{
struct ext2_fs_context *ctx;
- ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+ ctx = kzalloc_obj(*ctx, GFP_KERNEL);
if (!ctx)
return -ENOMEM;