Commit 540c53d1 authored by Mark Brown's avatar Mark Brown

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.
parents f82ecf76 bce84306
...@@ -132,9 +132,9 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min, ...@@ -132,9 +132,9 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
lower_index = mas.index; lower_index = mas.index;
lower_last = min -1; lower_last = min -1;
lower = kmemdup(entry, ((min - mas.index) * lower = kmemdup_array(entry,
sizeof(unsigned long)), min - mas.index, sizeof(*lower),
map->alloc_flags); map->alloc_flags);
if (!lower) { if (!lower) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_unlocked; goto out_unlocked;
...@@ -145,10 +145,9 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min, ...@@ -145,10 +145,9 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
upper_index = max + 1; upper_index = max + 1;
upper_last = mas.last; upper_last = mas.last;
upper = kmemdup(&entry[max - mas.index + 1], upper = kmemdup_array(&entry[max - mas.index + 1],
((mas.last - max) * mas.last - max, sizeof(*upper),
sizeof(unsigned long)), map->alloc_flags);
map->alloc_flags);
if (!upper) { if (!upper) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_unlocked; goto out_unlocked;
......
...@@ -170,8 +170,8 @@ int regcache_init(struct regmap *map, const struct regmap_config *config) ...@@ -170,8 +170,8 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
* a copy of it. * a copy of it.
*/ */
if (config->reg_defaults) { if (config->reg_defaults) {
tmp_buf = kmemdup(config->reg_defaults, map->num_reg_defaults * tmp_buf = kmemdup_array(config->reg_defaults, map->num_reg_defaults,
sizeof(struct reg_default), GFP_KERNEL); sizeof(*map->reg_defaults), GFP_KERNEL);
if (!tmp_buf) if (!tmp_buf)
return -ENOMEM; return -ENOMEM;
map->reg_defaults = tmp_buf; map->reg_defaults = tmp_buf;
...@@ -407,7 +407,7 @@ int regcache_sync(struct regmap *map) ...@@ -407,7 +407,7 @@ int regcache_sync(struct regmap *map)
* have gone out of sync, force writes of all the paging * have gone out of sync, force writes of all the paging
* registers. * 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 = struct regmap_range_node *this =
rb_entry(node, struct regmap_range_node, node); rb_entry(node, struct regmap_range_node, node);
......
...@@ -2347,7 +2347,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, ...@@ -2347,7 +2347,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
} else { } else {
void *wval; 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) if (!wval)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment