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/base/regmap | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
| download | lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.zip | |
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/base/regmap')
| -rw-r--r-- | drivers/base/regmap/regcache-flat.c | 2 | ||||
| -rw-r--r-- | drivers/base/regmap/regcache-maple.c | 2 | ||||
| -rw-r--r-- | drivers/base/regmap/regcache-rbtree.c | 4 | ||||
| -rw-r--r-- | drivers/base/regmap/regcache.c | 3 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-debugfs.c | 4 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-irq.c | 2 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-kunit.c | 4 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-mmio.c | 2 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-ram.c | 6 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-raw-ram.c | 6 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-spi-avmm.c | 2 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap-spi.c | 2 | ||||
| -rw-r--r-- | drivers/base/regmap/regmap.c | 8 |
13 files changed, 21 insertions, 26 deletions
diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c index c924817e19b1..025e6749bb24 100644 --- a/drivers/base/regmap/regcache-flat.c +++ b/drivers/base/regmap/regcache-flat.c @@ -36,7 +36,7 @@ static int regcache_flat_init(struct regmap *map) return -EINVAL; cache_size = regcache_flat_get_index(map, map->max_register) + 1; - cache = kzalloc(struct_size(cache, data, cache_size), map->alloc_flags); + cache = kzalloc_flex(*cache, data, cache_size, map->alloc_flags); if (!cache) return -ENOMEM; diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/regcache-maple.c index 4134a77ae1d6..49ba7282e4b8 100644 --- a/drivers/base/regmap/regcache-maple.c +++ b/drivers/base/regmap/regcache-maple.c @@ -294,7 +294,7 @@ static int regcache_maple_init(struct regmap *map) { struct maple_tree *mt; - mt = kmalloc(sizeof(*mt), map->alloc_flags); + mt = kmalloc_obj(*mt, map->alloc_flags); if (!mt) return -ENOMEM; map->cache = mt; diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c index 3344b82c3799..a69e8b4c359b 100644 --- a/drivers/base/regmap/regcache-rbtree.c +++ b/drivers/base/regmap/regcache-rbtree.c @@ -185,7 +185,7 @@ static int regcache_rbtree_init(struct regmap *map) { struct regcache_rbtree_ctx *rbtree_ctx; - map->cache = kmalloc(sizeof *rbtree_ctx, map->alloc_flags); + map->cache = kmalloc_obj(*rbtree_ctx, map->alloc_flags); if (!map->cache) return -ENOMEM; @@ -320,7 +320,7 @@ regcache_rbtree_node_alloc(struct regmap *map, unsigned int reg) const struct regmap_range *range; int i; - rbnode = kzalloc(sizeof(*rbnode), map->alloc_flags); + rbnode = kzalloc_obj(*rbnode, map->alloc_flags); if (!rbnode) return NULL; diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c index d596526dccbb..750a4c4b755e 100644 --- a/drivers/base/regmap/regcache.c +++ b/drivers/base/regmap/regcache.c @@ -66,8 +66,7 @@ static int regcache_hw_init(struct regmap *map) } map->num_reg_defaults = count; - map->reg_defaults = kmalloc_array(count, sizeof(struct reg_default), - GFP_KERNEL); + map->reg_defaults = kmalloc_objs(struct reg_default, count, GFP_KERNEL); if (!map->reg_defaults) return -ENOMEM; diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c index c9b4c04b1cf6..611ab7bbdeda 100644 --- a/drivers/base/regmap/regmap-debugfs.c +++ b/drivers/base/regmap/regmap-debugfs.c @@ -130,7 +130,7 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map, /* No cache entry? Start a new one */ if (!c) { - c = kzalloc(sizeof(*c), GFP_KERNEL); + c = kzalloc_obj(*c, GFP_KERNEL); if (!c) { regmap_debugfs_free_dump_cache(map); mutex_unlock(&map->cache_lock); @@ -555,7 +555,7 @@ void regmap_debugfs_init(struct regmap *map) /* If we don't have the debugfs root yet, postpone init */ if (!regmap_debugfs_root) { struct regmap_debugfs_node *node; - node = kzalloc(sizeof(*node), GFP_KERNEL); + node = kzalloc_obj(*node, GFP_KERNEL); if (!node) return; node->map = map; diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c index 6112d942499b..d3e9c6fef37d 100644 --- a/drivers/base/regmap/regmap-irq.c +++ b/drivers/base/regmap/regmap-irq.c @@ -706,7 +706,7 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode, } } - d = kzalloc(sizeof(*d), GFP_KERNEL); + d = kzalloc_obj(*d, GFP_KERNEL); if (!d) return -ENOMEM; diff --git a/drivers/base/regmap/regmap-kunit.c b/drivers/base/regmap/regmap-kunit.c index 6d8279de3ff2..e22bc2a0ea27 100644 --- a/drivers/base/regmap/regmap-kunit.c +++ b/drivers/base/regmap/regmap-kunit.c @@ -211,7 +211,7 @@ static struct regmap *gen_regmap(struct kunit *test, get_random_bytes(buf, size); - *data = kzalloc(sizeof(**data), GFP_KERNEL); + *data = kzalloc_obj(**data, GFP_KERNEL); if (!(*data)) goto out_free; (*data)->vals = buf; @@ -1759,7 +1759,7 @@ static struct regmap *gen_raw_regmap(struct kunit *test, get_random_bytes(buf, size); - *data = kzalloc(sizeof(**data), GFP_KERNEL); + *data = kzalloc_obj(**data, GFP_KERNEL); if (!(*data)) goto out_free; (*data)->vals = (void *)buf; diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c index 29e5f3175301..983ffe7f035a 100644 --- a/drivers/base/regmap/regmap-mmio.c +++ b/drivers/base/regmap/regmap-mmio.c @@ -430,7 +430,7 @@ static struct regmap_mmio_context *regmap_mmio_gen_context(struct device *dev, if (config->use_relaxed_mmio && config->io_port) return ERR_PTR(-EINVAL); - ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + ctx = kzalloc_obj(*ctx, GFP_KERNEL); if (!ctx) return ERR_PTR(-ENOMEM); diff --git a/drivers/base/regmap/regmap-ram.c b/drivers/base/regmap/regmap-ram.c index 4e5b4518ce4d..300745d400ee 100644 --- a/drivers/base/regmap/regmap-ram.c +++ b/drivers/base/regmap/regmap-ram.c @@ -66,13 +66,11 @@ struct regmap *__regmap_init_ram(struct device *dev, return ERR_PTR(-EINVAL); } - data->read = kcalloc(config->max_register + 1, sizeof(bool), - GFP_KERNEL); + data->read = kzalloc_objs(bool, config->max_register + 1, GFP_KERNEL); if (!data->read) return ERR_PTR(-ENOMEM); - data->written = kcalloc(config->max_register + 1, sizeof(bool), - GFP_KERNEL); + data->written = kzalloc_objs(bool, config->max_register + 1, GFP_KERNEL); if (!data->written) return ERR_PTR(-ENOMEM); diff --git a/drivers/base/regmap/regmap-raw-ram.c b/drivers/base/regmap/regmap-raw-ram.c index 76c98814fb8a..6a87df7269c6 100644 --- a/drivers/base/regmap/regmap-raw-ram.c +++ b/drivers/base/regmap/regmap-raw-ram.c @@ -123,13 +123,11 @@ struct regmap *__regmap_init_raw_ram(struct device *dev, return ERR_PTR(-EINVAL); } - data->read = kcalloc(config->max_register + 1, sizeof(bool), - GFP_KERNEL); + data->read = kzalloc_objs(bool, config->max_register + 1, GFP_KERNEL); if (!data->read) return ERR_PTR(-ENOMEM); - data->written = kcalloc(config->max_register + 1, sizeof(bool), - GFP_KERNEL); + data->written = kzalloc_objs(bool, config->max_register + 1, GFP_KERNEL); if (!data->written) return ERR_PTR(-ENOMEM); diff --git a/drivers/base/regmap/regmap-spi-avmm.c b/drivers/base/regmap/regmap-spi-avmm.c index d86a06cadcdb..d5cfa8eeffdc 100644 --- a/drivers/base/regmap/regmap-spi-avmm.c +++ b/drivers/base/regmap/regmap-spi-avmm.c @@ -630,7 +630,7 @@ spi_avmm_bridge_ctx_gen(struct spi_device *spi) return ERR_PTR(-EINVAL); } - br = kzalloc(sizeof(*br), GFP_KERNEL); + br = kzalloc_obj(*br, GFP_KERNEL); if (!br) return ERR_PTR(-ENOMEM); diff --git a/drivers/base/regmap/regmap-spi.c b/drivers/base/regmap/regmap-spi.c index 14b1d88997cb..56cad7763f56 100644 --- a/drivers/base/regmap/regmap-spi.c +++ b/drivers/base/regmap/regmap-spi.c @@ -81,7 +81,7 @@ static struct regmap_async *regmap_spi_async_alloc(void) { struct regmap_async_spi *async_spi; - async_spi = kzalloc(sizeof(*async_spi), GFP_KERNEL); + async_spi = kzalloc_obj(*async_spi, GFP_KERNEL); if (!async_spi) return NULL; diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 4231e9d4b8ff..443dc31f69d3 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -689,7 +689,7 @@ struct regmap *__regmap_init(struct device *dev, if (!config) goto err; - map = kzalloc(sizeof(*map), GFP_KERNEL); + map = kzalloc_obj(*map, GFP_KERNEL); if (map == NULL) { ret = -ENOMEM; goto err; @@ -1117,7 +1117,7 @@ skip_format_initialization: } } - new = kzalloc(sizeof(*new), GFP_KERNEL); + new = kzalloc_obj(*new, GFP_KERNEL); if (new == NULL) { ret = -ENOMEM; goto err_range; @@ -1274,7 +1274,7 @@ int regmap_field_bulk_alloc(struct regmap *regmap, struct regmap_field *rf; int i; - rf = kcalloc(num_fields, sizeof(*rf), GFP_KERNEL); + rf = kzalloc_objs(*rf, num_fields, GFP_KERNEL); if (!rf) return -ENOMEM; @@ -1384,7 +1384,7 @@ EXPORT_SYMBOL_GPL(devm_regmap_field_free); struct regmap_field *regmap_field_alloc(struct regmap *regmap, struct reg_field reg_field) { - struct regmap_field *rm_field = kzalloc(sizeof(*rm_field), GFP_KERNEL); + struct regmap_field *rm_field = kzalloc_obj(*rm_field, GFP_KERNEL); if (!rm_field) return ERR_PTR(-ENOMEM); |
