regmap: cache: mapple: use kmalloc_array() to replace kmalloc()
Subsystems (2)
PATCH 1/1 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.
--- drivers/base/regmap/regcache-maple.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/base/regmap/regcache-maple.c +3 -4
@@ -73,8 +73,7 @@ static int regcache_maple_write(struct regmap *map, unsigned int reg,rcu_read_unlock (); - entry =kmalloc ((last - index +1 ) *sizeof (unsigned long ), - map->alloc_flags); + entry =kmalloc_array (last - index +1 ,sizeof (*entry), map->alloc_flags);if (!entry)return -ENOMEM ;
@@ -204,7 +203,7 @@ static int regcache_maple_sync_block(struct regmap *map, unsigned long *entry,* overheads. */ if (max - min >1 &®map_can_raw_write (map)) { - buf =kmalloc (val_bytes * (max - min), map->alloc_flags); + buf =kmalloc_array (max - min, val_bytes, map->alloc_flags);if (!buf) { ret = -ENOMEM ; goto out;
@@ -320,7 +319,7 @@ static int regcache_maple_insert_block(struct regmap *map, int first,unsigned long *entry;int i, ret; - entry =kcalloc (last - first +1 ,sizeof (unsigned long ), map->alloc_flags); + entry =kmalloc_array (last - first +1 ,sizeof (*entry), map->alloc_flags);if (!entry)return -ENOMEM ;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Mark Brown
maintainerQuoted 6 lines · Andy Shevchenko
Use
kmalloc_array()to replacekmalloc()with multiplication.kmalloc_array()has multiply overflow check, which will be safer. In once case changekcalloc()as we don't need to clear the memory since it's all being reinitialised just immediately after that.
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next
Thanks!
[1/1] regmap: cache: mapple: use kmalloc_array() to replace kmalloc()
commit: 37c95f022a7a34823c123eeccdfe415b88562867
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark