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/md/dm-pcache | |
| 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/md/dm-pcache')
| -rw-r--r-- | drivers/md/dm-pcache/cache.c | 3 | ||||
| -rw-r--r-- | drivers/md/dm-pcache/cache_key.c | 3 | ||||
| -rw-r--r-- | drivers/md/dm-pcache/dm_pcache.c | 2 |
3 files changed, 5 insertions, 3 deletions
diff --git a/drivers/md/dm-pcache/cache.c b/drivers/md/dm-pcache/cache.c index 534bf07b794f..a616255b83e2 100644 --- a/drivers/md/dm-pcache/cache.c +++ b/drivers/md/dm-pcache/cache.c @@ -138,7 +138,8 @@ static int cache_init(struct dm_pcache *pcache) struct pcache_cache_dev *cache_dev = &pcache->cache_dev; int ret; - cache->segments = kvcalloc(cache_dev->seg_num, sizeof(struct pcache_cache_segment), GFP_KERNEL); + cache->segments = kvzalloc_objs(struct pcache_cache_segment, + cache_dev->seg_num, GFP_KERNEL); if (!cache->segments) { ret = -ENOMEM; goto err; diff --git a/drivers/md/dm-pcache/cache_key.c b/drivers/md/dm-pcache/cache_key.c index 2b77e121f89b..3de356abf952 100644 --- a/drivers/md/dm-pcache/cache_key.c +++ b/drivers/md/dm-pcache/cache_key.c @@ -837,7 +837,8 @@ int cache_tree_init(struct pcache_cache *cache, struct pcache_cache_tree *cache_ * Each element is a cache tree structure that contains * an RB tree root and a spinlock for protecting its contents. */ - cache_tree->subtrees = kvcalloc(cache_tree->n_subtrees, sizeof(struct pcache_cache_subtree), GFP_KERNEL); + cache_tree->subtrees = kvzalloc_objs(struct pcache_cache_subtree, + cache_tree->n_subtrees, GFP_KERNEL); if (!cache_tree->subtrees) { ret = -ENOMEM; goto key_pool_exit; diff --git a/drivers/md/dm-pcache/dm_pcache.c b/drivers/md/dm-pcache/dm_pcache.c index e5f5936fa6f0..c36f2afdadc1 100644 --- a/drivers/md/dm-pcache/dm_pcache.c +++ b/drivers/md/dm-pcache/dm_pcache.c @@ -281,7 +281,7 @@ static int dm_pcache_ctr(struct dm_target *ti, unsigned int argc, char **argv) } /* Allocate memory for the cache structure */ - pcache = kzalloc(sizeof(struct dm_pcache), GFP_KERNEL); + pcache = kzalloc_obj(struct dm_pcache, GFP_KERNEL); if (!pcache) return -ENOMEM; |
