diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/nvdimm/btt.c | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (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 'drivers/nvdimm/btt.c')
| -rw-r--r-- | drivers/nvdimm/btt.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c index 237edfa1c624..c47785274d3a 100644 --- a/drivers/nvdimm/btt.c +++ b/drivers/nvdimm/btt.c @@ -539,8 +539,8 @@ static int btt_freelist_init(struct arena_info *arena) struct log_entry log_new; u32 i, map_entry, log_oldmap, log_newmap; - arena->freelist = kcalloc(arena->nfree, sizeof(struct free_entry), - GFP_KERNEL); + arena->freelist = kzalloc_objs(struct free_entry, arena->nfree, + GFP_KERNEL); if (!arena->freelist) return -ENOMEM; @@ -733,8 +733,8 @@ static int btt_maplocks_init(struct arena_info *arena) { u32 i; - arena->map_locks = kcalloc(arena->nfree, sizeof(struct aligned_lock), - GFP_KERNEL); + arena->map_locks = kzalloc_objs(struct aligned_lock, arena->nfree, + GFP_KERNEL); if (!arena->map_locks) return -ENOMEM; @@ -751,7 +751,7 @@ static struct arena_info *alloc_arena(struct btt *btt, size_t size, u64 logsize, mapsize, datasize; u64 available = size; - arena = kzalloc(sizeof(*arena), GFP_KERNEL); + arena = kzalloc_obj(*arena, GFP_KERNEL); if (!arena) return NULL; arena->nd_btt = btt->nd_btt; @@ -854,7 +854,7 @@ static int discover_arenas(struct btt *btt) size_t cur_off = 0; int num_arenas = 0; - struct btt_sb *super __free(kfree) = kzalloc(sizeof(*super), GFP_KERNEL); + struct btt_sb *super __free(kfree) = kzalloc_obj(*super, GFP_KERNEL); if (!super) return -ENOMEM; @@ -978,7 +978,7 @@ static int btt_arena_write_layout(struct arena_info *arena) if (ret) return ret; - super = kzalloc(sizeof(*super), GFP_NOIO); + super = kzalloc_obj(*super, GFP_NOIO); if (!super) return -ENOMEM; |
