summaryrefslogtreecommitdiff
path: root/block/partitions
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 /block/partitions
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 'block/partitions')
-rw-r--r--block/partitions/aix.c2
-rw-r--r--block/partitions/cmdline.c4
-rw-r--r--block/partitions/core.c2
-rw-r--r--block/partitions/efi.c2
-rw-r--r--block/partitions/ibm.c6
-rw-r--r--block/partitions/ldm.c10
6 files changed, 13 insertions, 13 deletions
diff --git a/block/partitions/aix.c b/block/partitions/aix.c
index 85f4b967565e..97c8fa2a866f 100644
--- a/block/partitions/aix.c
+++ b/block/partitions/aix.c
@@ -199,7 +199,7 @@ int aix_partition(struct parsed_partitions *state)
numlvs = be16_to_cpu(p->numlvs);
put_dev_sector(sect);
}
- lvip = kcalloc(state->limit, sizeof(struct lv_info), GFP_KERNEL);
+ lvip = kzalloc_objs(struct lv_info, state->limit, GFP_KERNEL);
if (!lvip)
return 0;
if (numlvs && (d = read_part_sector(state, vgda_sector + 1, &sect))) {
diff --git a/block/partitions/cmdline.c b/block/partitions/cmdline.c
index da3e719d8e51..5d604a64842e 100644
--- a/block/partitions/cmdline.c
+++ b/block/partitions/cmdline.c
@@ -46,7 +46,7 @@ static int parse_subpart(struct cmdline_subpart **subpart, char *partdef)
*subpart = NULL;
- new_subpart = kzalloc(sizeof(struct cmdline_subpart), GFP_KERNEL);
+ new_subpart = kzalloc_obj(struct cmdline_subpart, GFP_KERNEL);
if (!new_subpart)
return -ENOMEM;
@@ -122,7 +122,7 @@ static int parse_parts(struct cmdline_parts **parts, char *bdevdef)
*parts = NULL;
- newparts = kzalloc(sizeof(struct cmdline_parts), GFP_KERNEL);
+ newparts = kzalloc_obj(struct cmdline_parts, GFP_KERNEL);
if (!newparts)
return -ENOMEM;
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 079057ab535a..189ab5650351 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -94,7 +94,7 @@ static struct parsed_partitions *allocate_partitions(struct gendisk *hd)
struct parsed_partitions *state;
int nr = DISK_MAX_PARTS;
- state = kzalloc(sizeof(*state), GFP_KERNEL);
+ state = kzalloc_obj(*state, GFP_KERNEL);
if (!state)
return NULL;
diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index 638261e9f2fb..ff145c6306e0 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -595,7 +595,7 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
lastlba = last_lba(state->disk);
if (!force_gpt) {
/* This will be added to the EFI Spec. per Intel after v1.02. */
- legacymbr = kzalloc(sizeof(*legacymbr), GFP_KERNEL);
+ legacymbr = kzalloc_obj(*legacymbr, GFP_KERNEL);
if (!legacymbr)
goto fail;
diff --git a/block/partitions/ibm.c b/block/partitions/ibm.c
index 631291fbb356..b81b7a690787 100644
--- a/block/partitions/ibm.c
+++ b/block/partitions/ibm.c
@@ -347,13 +347,13 @@ int ibm_partition(struct parsed_partitions *state)
nr_sectors = bdev_nr_sectors(bdev);
if (nr_sectors == 0)
goto out_symbol;
- info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
+ info = kmalloc_obj(dasd_information2_t, GFP_KERNEL);
if (info == NULL)
goto out_symbol;
- geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL);
+ geo = kmalloc_obj(struct hd_geometry, GFP_KERNEL);
if (geo == NULL)
goto out_nogeo;
- label = kmalloc(sizeof(union label_t), GFP_KERNEL);
+ label = kmalloc_obj(union label_t, GFP_KERNEL);
if (label == NULL)
goto out_nolab;
/* set start if not filled by getgeo function e.g. virtblk */
diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c
index 2bd42fedb907..27ffddd74e11 100644
--- a/block/partitions/ldm.c
+++ b/block/partitions/ldm.c
@@ -273,8 +273,8 @@ static bool ldm_validate_privheads(struct parsed_partitions *state,
BUG_ON (!state || !ph1);
- ph[1] = kmalloc (sizeof (*ph[1]), GFP_KERNEL);
- ph[2] = kmalloc (sizeof (*ph[2]), GFP_KERNEL);
+ ph[1] = kmalloc_obj(*ph[1], GFP_KERNEL);
+ ph[2] = kmalloc_obj(*ph[2], GFP_KERNEL);
if (!ph[1] || !ph[2]) {
ldm_crit ("Out of memory.");
goto out;
@@ -362,7 +362,7 @@ static bool ldm_validate_tocblocks(struct parsed_partitions *state,
BUG_ON(!state || !ldb);
ph = &ldb->ph;
tb[0] = &ldb->toc;
- tb[1] = kmalloc_array(3, sizeof(*tb[1]), GFP_KERNEL);
+ tb[1] = kmalloc_objs(*tb[1], 3, GFP_KERNEL);
if (!tb[1]) {
ldm_crit("Out of memory.");
goto err;
@@ -1158,7 +1158,7 @@ static bool ldm_ldmdb_add (u8 *data, int len, struct ldmdb *ldb)
BUG_ON (!data || !ldb);
- vb = kmalloc (sizeof (*vb), GFP_KERNEL);
+ vb = kmalloc_obj(*vb, GFP_KERNEL);
if (!vb) {
ldm_crit ("Out of memory.");
return false;
@@ -1438,7 +1438,7 @@ int ldm_partition(struct parsed_partitions *state)
if (!ldm_validate_partition_table(state))
return 0;
- ldb = kmalloc (sizeof (*ldb), GFP_KERNEL);
+ ldb = kmalloc_obj(*ldb, GFP_KERNEL);
if (!ldb) {
ldm_crit ("Out of memory.");
goto out;