summaryrefslogtreecommitdiff
path: root/fs/jbd2
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/jbd2
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/jbd2')
-rw-r--r--fs/jbd2/journal.c11
-rw-r--r--fs/jbd2/revoke.c2
2 files changed, 6 insertions, 7 deletions
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index c973162d5b31..05ea1e5af80d 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1175,7 +1175,7 @@ static int jbd2_seq_info_open(struct inode *inode, struct file *file)
struct jbd2_stats_proc_session *s;
int rc, size;
- s = kmalloc(sizeof(*s), GFP_KERNEL);
+ s = kmalloc_obj(*s, GFP_KERNEL);
if (s == NULL)
return -ENOMEM;
size = sizeof(struct transaction_stats_s);
@@ -1525,7 +1525,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
int err;
int n;
- journal = kzalloc(sizeof(*journal), GFP_KERNEL);
+ journal = kzalloc_obj(*journal, GFP_KERNEL);
if (!journal)
return ERR_PTR(-ENOMEM);
@@ -1578,8 +1578,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
n = journal->j_blocksize / jbd2_min_tag_size();
journal->j_wbufsize = n;
journal->j_fc_wbuf = NULL;
- journal->j_wbuf = kmalloc_array(n, sizeof(struct buffer_head *),
- GFP_KERNEL);
+ journal->j_wbuf = kmalloc_objs(struct buffer_head *, n, GFP_KERNEL);
if (!journal->j_wbuf)
goto err_cleanup;
@@ -2269,8 +2268,8 @@ jbd2_journal_initialize_fast_commit(journal_t *journal)
/* Are we called twice? */
WARN_ON(journal->j_fc_wbuf != NULL);
- journal->j_fc_wbuf = kmalloc_array(num_fc_blks,
- sizeof(struct buffer_head *), GFP_KERNEL);
+ journal->j_fc_wbuf = kmalloc_objs(struct buffer_head *, num_fc_blks,
+ GFP_KERNEL);
if (!journal->j_fc_wbuf)
return -ENOMEM;
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index 1467f6790747..3aa9f82a8ef7 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -231,7 +231,7 @@ struct jbd2_revoke_table_s *jbd2_journal_init_revoke_table(int hash_size)
table->hash_size = hash_size;
table->hash_shift = shift;
table->hash_table =
- kvmalloc_array(hash_size, sizeof(struct list_head), GFP_KERNEL);
+ kvmalloc_objs(struct list_head, hash_size, GFP_KERNEL);
if (!table->hash_table) {
kmem_cache_free(jbd2_revoke_table_cache, table);
table = NULL;