mirror of https://github.com/torvalds/linux.git
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>
This commit is contained in:
parent
37c95f022a
commit
b95cacd8d7
|
|
@ -275,18 +275,16 @@ static int regcache_rbtree_insert_to_block(struct regmap *map,
|
|||
pos = (reg - base_reg) / map->reg_stride;
|
||||
offset = (rbnode->base_reg - base_reg) / map->reg_stride;
|
||||
|
||||
blk = krealloc(rbnode->block,
|
||||
blklen * map->cache_word_size,
|
||||
map->alloc_flags);
|
||||
blk = krealloc_array(rbnode->block, blklen, map->cache_word_size, map->alloc_flags);
|
||||
if (!blk)
|
||||
return -ENOMEM;
|
||||
|
||||
rbnode->block = blk;
|
||||
|
||||
if (BITS_TO_LONGS(blklen) > BITS_TO_LONGS(rbnode->blklen)) {
|
||||
present = krealloc(rbnode->cache_present,
|
||||
BITS_TO_LONGS(blklen) * sizeof(*present),
|
||||
map->alloc_flags);
|
||||
present = krealloc_array(rbnode->cache_present,
|
||||
BITS_TO_LONGS(blklen), sizeof(*present),
|
||||
map->alloc_flags);
|
||||
if (!present)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue