Skip to content

Commit 37c95f0

Browse files
andy-shevbroonie
authored andcommitted
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>
1 parent 40384c8 commit 37c95f0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/base/regmap/regcache-maple.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ static int regcache_maple_write(struct regmap *map, unsigned int reg,
7373

7474
rcu_read_unlock();
7575

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);
7877
if (!entry)
7978
return -ENOMEM;
8079

@@ -204,7 +203,7 @@ static int regcache_maple_sync_block(struct regmap *map, unsigned long *entry,
204203
* overheads.
205204
*/
206205
if (max - min > 1 && regmap_can_raw_write(map)) {
207-
buf = kmalloc(val_bytes * (max - min), map->alloc_flags);
206+
buf = kmalloc_array(max - min, val_bytes, map->alloc_flags);
208207
if (!buf) {
209208
ret = -ENOMEM;
210209
goto out;
@@ -320,7 +319,7 @@ static int regcache_maple_insert_block(struct regmap *map, int first,
320319
unsigned long *entry;
321320
int i, ret;
322321

323-
entry = kcalloc(last - first + 1, sizeof(unsigned long), map->alloc_flags);
322+
entry = kmalloc_array(last - first + 1, sizeof(*entry), map->alloc_flags);
324323
if (!entry)
325324
return -ENOMEM;
326325

0 commit comments

Comments
 (0)