]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
regmap: maple: Switch to use kmemdup_array()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 6 Jun 2024 16:46:25 +0000 (19:46 +0300)
committerMark Brown <broonie@kernel.org>
Fri, 7 Jun 2024 13:28:23 +0000 (14:28 +0100)
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>
drivers/base/regmap/regcache-maple.c

index e4243340485497d8fed2107c5128c59df5f16f6f..f0df2da6d522e7e3949eb91695addea16b908759 100644 (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;