Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regmap: cache: mapple: use kmalloc_array() to replace kmalloc()

Use kmalloc_array() to replace kmalloc() with multiplication.
kmalloc_array() has multiply overflow check, which will be safer.
In once case change kcalloc() as we don't need to clear the memory
since it's all being reinitialised just immediately after that.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20241121123433.4180133-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Andy Shevchenko and committed by
Mark Brown
37c95f02 40384c84

+3 -4
+3 -4
drivers/base/regmap/regcache-maple.c
··· 73 73 74 74 rcu_read_unlock(); 75 75 76 - entry = kmalloc((last - index + 1) * sizeof(unsigned long), 77 - map->alloc_flags); 76 + entry = kmalloc_array(last - index + 1, sizeof(*entry), map->alloc_flags); 78 77 if (!entry) 79 78 return -ENOMEM; 80 79 ··· 203 204 * overheads. 204 205 */ 205 206 if (max - min > 1 && regmap_can_raw_write(map)) { 206 - buf = kmalloc(val_bytes * (max - min), map->alloc_flags); 207 + buf = kmalloc_array(max - min, val_bytes, map->alloc_flags); 207 208 if (!buf) { 208 209 ret = -ENOMEM; 209 210 goto out; ··· 319 320 unsigned long *entry; 320 321 int i, ret; 321 322 322 - entry = kcalloc(last - first + 1, sizeof(unsigned long), map->alloc_flags); 323 + entry = kmalloc_array(last - first + 1, sizeof(*entry), map->alloc_flags); 323 324 if (!entry) 324 325 return -ENOMEM; 325 326