summaryrefslogtreecommitdiff
path: root/fs/jffs2
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/jffs2
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/jffs2')
-rw-r--r--fs/jffs2/acl.c3
-rw-r--r--fs/jffs2/erase.c2
-rw-r--r--fs/jffs2/fs.c3
-rw-r--r--fs/jffs2/readinode.c2
-rw-r--r--fs/jffs2/scan.c2
-rw-r--r--fs/jffs2/summary.c18
-rw-r--r--fs/jffs2/super.c2
-rw-r--r--fs/jffs2/wbuf.c2
-rw-r--r--fs/jffs2/xattr.c4
9 files changed, 21 insertions, 17 deletions
diff --git a/fs/jffs2/acl.c b/fs/jffs2/acl.c
index 888a7ceb6479..b7ece06cad80 100644
--- a/fs/jffs2/acl.c
+++ b/fs/jffs2/acl.c
@@ -133,8 +133,7 @@ static void *jffs2_acl_to_medium(const struct posix_acl *acl, size_t *size)
size_t i;
*size = jffs2_acl_size(acl->a_count);
- header = kmalloc(struct_size(header, a_entries, acl->a_count),
- GFP_KERNEL);
+ header = kmalloc_flex(*header, a_entries, acl->a_count, GFP_KERNEL);
if (!header)
return ERR_PTR(-ENOMEM);
header->a_version = cpu_to_je32(JFFS2_ACL_VERSION);
diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
index fda9f4d6093f..d451c8a1fdac 100644
--- a/fs/jffs2/erase.c
+++ b/fs/jffs2/erase.c
@@ -43,7 +43,7 @@ static void jffs2_erase_block(struct jffs2_sb_info *c,
jffs2_dbg(1, "%s(): erase block %#08x (range %#08x-%#08x)\n",
__func__,
jeb->offset, jeb->offset, jeb->offset + c->sector_size);
- instr = kzalloc(sizeof(struct erase_info), GFP_KERNEL);
+ instr = kzalloc_obj(struct erase_info, GFP_KERNEL);
if (!instr) {
pr_warn("kzalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n");
mutex_lock(&c->erase_free_sem);
diff --git a/fs/jffs2/fs.c b/fs/jffs2/fs.c
index 764bba8ba999..ff469d44b92f 100644
--- a/fs/jffs2/fs.c
+++ b/fs/jffs2/fs.c
@@ -562,7 +562,8 @@ int jffs2_do_fill_super(struct super_block *sb, struct fs_context *fc)
return ret;
c->inocache_hashsize = calculate_inocache_hashsize(c->flash_size);
- c->inocache_list = kcalloc(c->inocache_hashsize, sizeof(struct jffs2_inode_cache *), GFP_KERNEL);
+ c->inocache_list = kzalloc_objs(struct jffs2_inode_cache *,
+ c->inocache_hashsize, GFP_KERNEL);
if (!c->inocache_list) {
ret = -ENOMEM;
goto out_wbuf;
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index f987f78a894e..eeca922d4da4 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -1392,7 +1392,7 @@ int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
int jffs2_do_crccheck_inode(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic)
{
struct jffs2_raw_inode n;
- struct jffs2_inode_info *f = kzalloc(sizeof(*f), GFP_KERNEL);
+ struct jffs2_inode_info *f = kzalloc_obj(*f, GFP_KERNEL);
int ret;
if (!f)
diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c
index 62879c218d4b..39063e2131d6 100644
--- a/fs/jffs2/scan.c
+++ b/fs/jffs2/scan.c
@@ -132,7 +132,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
}
if (jffs2_sum_active()) {
- s = kzalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
+ s = kzalloc_obj(struct jffs2_summary, GFP_KERNEL);
if (!s) {
JFFS2_WARNING("Can't allocate memory for summary\n");
ret = -ENOMEM;
diff --git a/fs/jffs2/summary.c b/fs/jffs2/summary.c
index d83372d3e1a0..b9df829eff56 100644
--- a/fs/jffs2/summary.c
+++ b/fs/jffs2/summary.c
@@ -27,7 +27,7 @@ int jffs2_sum_init(struct jffs2_sb_info *c)
{
uint32_t sum_size = min_t(uint32_t, c->sector_size, MAX_SUMMARY_SIZE);
- c->summary = kzalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
+ c->summary = kzalloc_obj(struct jffs2_summary, GFP_KERNEL);
if (!c->summary) {
JFFS2_WARNING("Can't allocate memory for summary information!\n");
@@ -115,7 +115,8 @@ int jffs2_sum_add_padding_mem(struct jffs2_summary *s, uint32_t size)
int jffs2_sum_add_inode_mem(struct jffs2_summary *s, struct jffs2_raw_inode *ri,
uint32_t ofs)
{
- struct jffs2_sum_inode_mem *temp = kmalloc(sizeof(struct jffs2_sum_inode_mem), GFP_KERNEL);
+ struct jffs2_sum_inode_mem *temp = kmalloc_obj(struct jffs2_sum_inode_mem,
+ GFP_KERNEL);
if (!temp)
return -ENOMEM;
@@ -159,7 +160,7 @@ int jffs2_sum_add_xattr_mem(struct jffs2_summary *s, struct jffs2_raw_xattr *rx,
{
struct jffs2_sum_xattr_mem *temp;
- temp = kmalloc(sizeof(struct jffs2_sum_xattr_mem), GFP_KERNEL);
+ temp = kmalloc_obj(struct jffs2_sum_xattr_mem, GFP_KERNEL);
if (!temp)
return -ENOMEM;
@@ -177,7 +178,7 @@ int jffs2_sum_add_xref_mem(struct jffs2_summary *s, struct jffs2_raw_xref *rr, u
{
struct jffs2_sum_xref_mem *temp;
- temp = kmalloc(sizeof(struct jffs2_sum_xref_mem), GFP_KERNEL);
+ temp = kmalloc_obj(struct jffs2_sum_xref_mem, GFP_KERNEL);
if (!temp)
return -ENOMEM;
@@ -263,7 +264,8 @@ int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
switch (je16_to_cpu(node->u.nodetype)) {
case JFFS2_NODETYPE_INODE: {
struct jffs2_sum_inode_mem *temp =
- kmalloc(sizeof(struct jffs2_sum_inode_mem), GFP_KERNEL);
+ kmalloc_obj(struct jffs2_sum_inode_mem,
+ GFP_KERNEL);
if (!temp)
goto no_mem;
@@ -314,7 +316,8 @@ int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
#ifdef CONFIG_JFFS2_FS_XATTR
case JFFS2_NODETYPE_XATTR: {
struct jffs2_sum_xattr_mem *temp;
- temp = kmalloc(sizeof(struct jffs2_sum_xattr_mem), GFP_KERNEL);
+ temp = kmalloc_obj(struct jffs2_sum_xattr_mem,
+ GFP_KERNEL);
if (!temp)
goto no_mem;
@@ -329,7 +332,8 @@ int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
}
case JFFS2_NODETYPE_XREF: {
struct jffs2_sum_xref_mem *temp;
- temp = kmalloc(sizeof(struct jffs2_sum_xref_mem), GFP_KERNEL);
+ temp = kmalloc_obj(struct jffs2_sum_xref_mem,
+ GFP_KERNEL);
if (!temp)
goto no_mem;
temp->nodetype = node->r.nodetype;
diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c
index 4545f885c41e..48fbf1594ce8 100644
--- a/fs/jffs2/super.c
+++ b/fs/jffs2/super.c
@@ -311,7 +311,7 @@ static int jffs2_init_fs_context(struct fs_context *fc)
{
struct jffs2_sb_info *ctx;
- ctx = kzalloc(sizeof(struct jffs2_sb_info), GFP_KERNEL);
+ ctx = kzalloc_obj(struct jffs2_sb_info, GFP_KERNEL);
if (!ctx)
return -ENOMEM;
diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index 3ab3f0ff7ebb..9775b9b84504 100644
--- a/fs/jffs2/wbuf.c
+++ b/fs/jffs2/wbuf.c
@@ -92,7 +92,7 @@ static void jffs2_wbuf_dirties_inode(struct jffs2_sb_info *c, uint32_t ino)
if (jffs2_wbuf_pending_for_ino(c, ino))
return;
- new = kmalloc(sizeof(*new), GFP_KERNEL);
+ new = kmalloc_obj(*new, GFP_KERNEL);
if (!new) {
jffs2_dbg(1, "No memory to allocate inodirty. Fallback to all considered dirty\n");
jffs2_clear_wbuf_ino_list(c);
diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c
index defb4162c3d5..4452e6837b34 100644
--- a/fs/jffs2/xattr.c
+++ b/fs/jffs2/xattr.c
@@ -784,8 +784,8 @@ int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
- xref_tmphash = kcalloc(XREF_TMPHASH_SIZE,
- sizeof(struct jffs2_xattr_ref *), GFP_KERNEL);
+ xref_tmphash = kzalloc_objs(struct jffs2_xattr_ref *, XREF_TMPHASH_SIZE,
+ GFP_KERNEL);
if (!xref_tmphash)
return -ENOMEM;