Skip to content

Commit b95cacd

Browse files
andy-shevbroonie
authored andcommitted
regmap: cache: rbtree: use krealloc_array() to replace krealloc()
Use krealloc_array() to replace krealloc() with multiplication. krealloc_array() has multiply overflow check, which will be safer. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Link: https://patch.msgid.link/20241121123439.4180167-1-andriy.shevchenko@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 37c95f0 commit b95cacd

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

drivers/base/regmap/regcache-rbtree.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,16 @@ static int regcache_rbtree_insert_to_block(struct regmap *map,
275275
pos = (reg - base_reg) / map->reg_stride;
276276
offset = (rbnode->base_reg - base_reg) / map->reg_stride;
277277

278-
blk = krealloc(rbnode->block,
279-
blklen * map->cache_word_size,
280-
map->alloc_flags);
278+
blk = krealloc_array(rbnode->block, blklen, map->cache_word_size, map->alloc_flags);
281279
if (!blk)
282280
return -ENOMEM;
283281

284282
rbnode->block = blk;
285283

286284
if (BITS_TO_LONGS(blklen) > BITS_TO_LONGS(rbnode->blklen)) {
287-
present = krealloc(rbnode->cache_present,
288-
BITS_TO_LONGS(blklen) * sizeof(*present),
289-
map->alloc_flags);
285+
present = krealloc_array(rbnode->cache_present,
286+
BITS_TO_LONGS(blklen), sizeof(*present),
287+
map->alloc_flags);
290288
if (!present)
291289
return -ENOMEM;
292290

0 commit comments

Comments
 (0)