regmap: Switch to use kmemdup_array()

Merge series from Andy Shevchenko <andriy.shevchenko@linux.intel.com>:

Replace open coded kmemdup_array(), which does an additional
overflow check.

While at it, fix one minor issue in regcache.c.
This commit is contained in:
Mark Brown 2024-06-07 20:57:22 +01:00
commit 540c53d158
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
3 changed files with 10 additions and 11 deletions

View File

@ -132,9 +132,9 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
lower_index = mas.index;
lower_last = min -1;
lower = kmemdup(entry, ((min - mas.index) *
sizeof(unsigned long)),
map->alloc_flags);
lower = kmemdup_array(entry,
min - mas.index, sizeof(*lower),
map->alloc_flags);
if (!lower) {
ret = -ENOMEM;
goto out_unlocked;
@ -145,10 +145,9 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
upper_index = max + 1;
upper_last = mas.last;
upper = kmemdup(&entry[max - mas.index + 1],
((mas.last - max) *
sizeof(unsigned long)),
map->alloc_flags);
upper = kmemdup_array(&entry[max - mas.index + 1],
mas.last - max, sizeof(*upper),
map->alloc_flags);
if (!upper) {
ret = -ENOMEM;
goto out_unlocked;

View File

@ -170,8 +170,8 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
* a copy of it.
*/
if (config->reg_defaults) {
tmp_buf = kmemdup(config->reg_defaults, map->num_reg_defaults *
sizeof(struct reg_default), GFP_KERNEL);
tmp_buf = kmemdup_array(config->reg_defaults, map->num_reg_defaults,
sizeof(*map->reg_defaults), GFP_KERNEL);
if (!tmp_buf)
return -ENOMEM;
map->reg_defaults = tmp_buf;
@ -407,7 +407,7 @@ out:
* have gone out of sync, force writes of all the paging
* registers.
*/
rb_for_each(node, 0, &map->range_tree, rbtree_all) {
rb_for_each(node, NULL, &map->range_tree, rbtree_all) {
struct regmap_range_node *this =
rb_entry(node, struct regmap_range_node, node);

View File

@ -2347,7 +2347,7 @@ out:
} else {
void *wval;
wval = kmemdup(val, val_count * val_bytes, map->alloc_flags);
wval = kmemdup_array(val, val_count, val_bytes, map->alloc_flags);
if (!wval)
return -ENOMEM;