summaryrefslogtreecommitdiff
path: root/fs/udf
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/udf
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/udf')
-rw-r--r--fs/udf/super.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/fs/udf/super.c b/fs/udf/super.c
index b2f168b0a0d1..365cb78097d3 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -270,7 +270,7 @@ static int udf_init_fs_context(struct fs_context *fc)
{
struct udf_options *uopt;
- uopt = kzalloc(sizeof(*uopt), GFP_KERNEL);
+ uopt = kzalloc_obj(*uopt, GFP_KERNEL);
if (!uopt)
return -ENOMEM;
@@ -320,7 +320,7 @@ static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
{
struct udf_sb_info *sbi = UDF_SB(sb);
- sbi->s_partmaps = kcalloc(count, sizeof(*sbi->s_partmaps), GFP_KERNEL);
+ sbi->s_partmaps = kzalloc_objs(*sbi->s_partmaps, count, GFP_KERNEL);
if (!sbi->s_partmaps) {
sbi->s_partitions = 0;
return -ENOMEM;
@@ -1047,8 +1047,7 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
struct udf_bitmap *bitmap;
int nr_groups = udf_compute_nr_groups(sb, index);
- bitmap = kvzalloc(struct_size(bitmap, s_block_bitmap, nr_groups),
- GFP_KERNEL);
+ bitmap = kvzalloc_flex(*bitmap, s_block_bitmap, nr_groups, GFP_KERNEL);
if (!bitmap)
return NULL;
@@ -1697,7 +1696,7 @@ static struct udf_vds_record *handle_partition_descriptor(
struct part_desc_seq_scan_data *new_loc;
unsigned int new_size = ALIGN(partnum, PART_DESC_ALLOC_STEP);
- new_loc = kcalloc(new_size, sizeof(*new_loc), GFP_KERNEL);
+ new_loc = kzalloc_objs(*new_loc, new_size, GFP_KERNEL);
if (!new_loc)
return ERR_PTR(-ENOMEM);
memcpy(new_loc, data->part_descs_loc,
@@ -1757,9 +1756,8 @@ static noinline int udf_process_sequence(
memset(data.vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
data.size_part_descs = PART_DESC_ALLOC_STEP;
data.num_part_descs = 0;
- data.part_descs_loc = kcalloc(data.size_part_descs,
- sizeof(*data.part_descs_loc),
- GFP_KERNEL);
+ data.part_descs_loc = kzalloc_objs(*data.part_descs_loc,
+ data.size_part_descs, GFP_KERNEL);
if (!data.part_descs_loc)
return -ENOMEM;
@@ -2158,7 +2156,7 @@ static int udf_fill_super(struct super_block *sb, struct fs_context *fc)
bool lvid_open = false;
int silent = fc->sb_flags & SB_SILENT;
- sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
+ sbi = kzalloc_obj(*sbi, GFP_KERNEL);
if (!sbi)
return -ENOMEM;