summaryrefslogtreecommitdiff
path: root/fs/pstore
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/pstore
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/pstore')
-rw-r--r--fs/pstore/blk.c2
-rw-r--r--fs/pstore/inode.c6
-rw-r--r--fs/pstore/platform.c2
-rw-r--r--fs/pstore/ram.c6
-rw-r--r--fs/pstore/ram_core.c9
-rw-r--r--fs/pstore/zone.c4
6 files changed, 14 insertions, 15 deletions
diff --git a/fs/pstore/blk.c b/fs/pstore/blk.c
index fa6b8cb788a1..0c9c8b6fdbb8 100644
--- a/fs/pstore/blk.c
+++ b/fs/pstore/blk.c
@@ -297,7 +297,7 @@ static int __init __best_effort_init(void)
return -EINVAL;
}
- best_effort_dev = kzalloc(sizeof(*best_effort_dev), GFP_KERNEL);
+ best_effort_dev = kzalloc_obj(*best_effort_dev, GFP_KERNEL);
if (!best_effort_dev)
return -ENOMEM;
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index 71deffcc3356..8ebcd231e09a 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -70,7 +70,7 @@ static void *pstore_ftrace_seq_start(struct seq_file *s, loff_t *pos)
struct pstore_private *ps = s->private;
struct pstore_ftrace_seq_data *data __free(kfree) = NULL;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return NULL;
@@ -365,7 +365,7 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
record->psi->name, record->id,
record->compressed ? ".enc.z" : "");
- private = kzalloc(sizeof(*private), GFP_KERNEL);
+ private = kzalloc_obj(*private, GFP_KERNEL);
if (!private)
return -ENOMEM;
@@ -477,7 +477,7 @@ static int pstore_init_fs_context(struct fs_context *fc)
{
struct pstore_context *ctx;
- ctx = kzalloc(sizeof(struct pstore_context), GFP_KERNEL);
+ ctx = kzalloc_obj(struct pstore_context, GFP_KERNEL);
if (!ctx)
return -ENOMEM;
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index f8b9c9c73997..ff9603bb89db 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -683,7 +683,7 @@ void pstore_get_backend_records(struct pstore_info *psi,
struct pstore_record *record;
int rc;
- record = kzalloc(sizeof(*record), GFP_KERNEL);
+ record = kzalloc_obj(*record, GFP_KERNEL);
if (!record) {
pr_err("out of memory creating record\n");
break;
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 39936d6da0dd..79f801c913bf 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -232,8 +232,8 @@ static ssize_t ramoops_pstore_read(struct pstore_record *record)
*/
struct persistent_ram_zone *tmp_prz, *prz_next;
- tmp_prz = kzalloc(sizeof(struct persistent_ram_zone),
- GFP_KERNEL);
+ tmp_prz = kzalloc_obj(struct persistent_ram_zone,
+ GFP_KERNEL);
if (!tmp_prz)
return -ENOMEM;
prz = tmp_prz;
@@ -539,7 +539,7 @@ static int ramoops_init_przs(const char *name,
goto fail;
}
- prz_ar = kcalloc(*cnt, sizeof(**przs), GFP_KERNEL);
+ prz_ar = kzalloc_objs(**przs, *cnt, GFP_KERNEL);
if (!prz_ar)
goto fail;
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index 7b6d6378a3b8..49d022b85d8a 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -229,9 +229,8 @@ static int persistent_ram_init_ecc(struct persistent_ram_zone *prz,
}
/* allocate workspace instead of using stack VLA */
- prz->ecc_info.par = kmalloc_array(prz->ecc_info.ecc_size,
- sizeof(*prz->ecc_info.par),
- GFP_KERNEL);
+ prz->ecc_info.par = kmalloc_objs(*prz->ecc_info.par,
+ prz->ecc_info.ecc_size, GFP_KERNEL);
if (!prz->ecc_info.par) {
pr_err("cannot allocate ECC parity workspace\n");
return -ENOMEM;
@@ -439,7 +438,7 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
return NULL;
}
- pages = kmalloc_array(page_count, sizeof(struct page *), GFP_KERNEL);
+ pages = kmalloc_objs(struct page *, page_count, GFP_KERNEL);
if (!pages) {
pr_err("%s: Failed to allocate array for %u pages\n",
__func__, page_count);
@@ -606,7 +605,7 @@ struct persistent_ram_zone *persistent_ram_new(phys_addr_t start, size_t size,
struct persistent_ram_zone *prz;
int ret = -ENOMEM;
- prz = kzalloc(sizeof(struct persistent_ram_zone), GFP_KERNEL);
+ prz = kzalloc_obj(struct persistent_ram_zone, GFP_KERNEL);
if (!prz) {
pr_err("failed to allocate persistent ram zone\n");
goto err;
diff --git a/fs/pstore/zone.c b/fs/pstore/zone.c
index eb61ba5bb964..6687d255a36b 100644
--- a/fs/pstore/zone.c
+++ b/fs/pstore/zone.c
@@ -1166,7 +1166,7 @@ static struct pstore_zone *psz_init_zone(enum pstore_type_id type,
return ERR_PTR(-ENOMEM);
}
- zone = kzalloc(sizeof(struct pstore_zone), GFP_KERNEL);
+ zone = kzalloc_obj(struct pstore_zone, GFP_KERNEL);
if (!zone)
return ERR_PTR(-ENOMEM);
@@ -1218,7 +1218,7 @@ static struct pstore_zone **psz_init_zones(enum pstore_type_id type,
return ERR_PTR(-EINVAL);
}
- zones = kcalloc(c, sizeof(*zones), GFP_KERNEL);
+ zones = kzalloc_objs(*zones, c, GFP_KERNEL);
if (!zones) {
pr_err("allocate for zones %s failed\n", name);
return ERR_PTR(-ENOMEM);