]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
regmap: cache: rbtree: use krealloc_array() to replace krealloc()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 21 Nov 2024 12:34:39 +0000 (14:34 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 2 Dec 2024 00:31:16 +0000 (00:31 +0000)
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>
drivers/base/regmap/regcache-rbtree.c

index 188438186589f686e13593e3e68fa42a27beb0ce..a9d17f316e55c48f93927351acdcda39df9c7ad2 100644 (file)
@@ -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;