Unverified Commit b95cacd8 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Mark Brown
Browse files

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: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patch.msgid.link/20241121123439.4180167-1-andriy.shevchenko@linux.intel.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 37c95f02
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -275,17 +275,15 @@ 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),
		present = krealloc_array(rbnode->cache_present,
					 BITS_TO_LONGS(blklen), sizeof(*present),
					 map->alloc_flags);
		if (!present)
			return -ENOMEM;