Skip to content

Commit 540c53d

Browse files
committed
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.
2 parents f82ecf7 + bce8430 commit 540c53d

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

drivers/base/regmap/regcache-maple.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
132132
lower_index = mas.index;
133133
lower_last = min -1;
134134

135-
lower = kmemdup(entry, ((min - mas.index) *
136-
sizeof(unsigned long)),
137-
map->alloc_flags);
135+
lower = kmemdup_array(entry,
136+
min - mas.index, sizeof(*lower),
137+
map->alloc_flags);
138138
if (!lower) {
139139
ret = -ENOMEM;
140140
goto out_unlocked;
@@ -145,10 +145,9 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min,
145145
upper_index = max + 1;
146146
upper_last = mas.last;
147147

148-
upper = kmemdup(&entry[max - mas.index + 1],
149-
((mas.last - max) *
150-
sizeof(unsigned long)),
151-
map->alloc_flags);
148+
upper = kmemdup_array(&entry[max - mas.index + 1],
149+
mas.last - max, sizeof(*upper),
150+
map->alloc_flags);
152151
if (!upper) {
153152
ret = -ENOMEM;
154153
goto out_unlocked;

drivers/base/regmap/regcache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
170170
* a copy of it.
171171
*/
172172
if (config->reg_defaults) {
173-
tmp_buf = kmemdup(config->reg_defaults, map->num_reg_defaults *
174-
sizeof(struct reg_default), GFP_KERNEL);
173+
tmp_buf = kmemdup_array(config->reg_defaults, map->num_reg_defaults,
174+
sizeof(*map->reg_defaults), GFP_KERNEL);
175175
if (!tmp_buf)
176176
return -ENOMEM;
177177
map->reg_defaults = tmp_buf;
@@ -407,7 +407,7 @@ int regcache_sync(struct regmap *map)
407407
* have gone out of sync, force writes of all the paging
408408
* registers.
409409
*/
410-
rb_for_each(node, 0, &map->range_tree, rbtree_all) {
410+
rb_for_each(node, NULL, &map->range_tree, rbtree_all) {
411411
struct regmap_range_node *this =
412412
rb_entry(node, struct regmap_range_node, node);
413413

drivers/base/regmap/regmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2347,7 +2347,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
23472347
} else {
23482348
void *wval;
23492349

2350-
wval = kmemdup(val, val_count * val_bytes, map->alloc_flags);
2350+
wval = kmemdup_array(val, val_count, val_bytes, map->alloc_flags);
23512351
if (!wval)
23522352
return -ENOMEM;
23532353

0 commit comments

Comments
 (0)