Skip to content

Commit bce8430

Browse files
andy-shevbroonie
authored andcommitted
regmap: maple: Switch to use kmemdup_array()
Let the kememdup_array() take care about multiplication and possible overflows. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://lore.kernel.org/r/20240606164717.3031107-5-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent f755d69 commit bce8430

1 file changed

Lines changed: 6 additions & 7 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;

0 commit comments

Comments
 (0)