regmap: Switch to use kmemdup_array()
Subsystems (2)
cover regmap: Switch to use kmemdup_array()
Replace open coded kmemdup_array(), which does an additional overflow check.
While at it, fix one minor issue in regcache.c.
Andy Shevchenko (4):
regmap: Switch to use kmemdup_array()
regmap: cache: Use correct type of the rb_for_each() parameter
regmap: cache: Switch to use kmemdup_array()
regmap: maple: Switch to use kmemdup_array()
drivers/base/regmap/regcache-maple.c | 13 ++++++------- drivers/base/regmap/regcache.c | 6 +++--- drivers/base/regmap/regmap.c | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH 1/4 regmap: Switch to use kmemdup_array()
Let the kememdup_array() take care about multiplication and possible overflows.
--- drivers/base/regmap/regmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/regmap/regmap.c +1 -1
@@ -2347,7 +2347,7 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, }else {void *wval; - wval =kmemdup (val, val_count * val_bytes, map->alloc_flags); + wval =kmemdup_array (val, val_count, val_bytes, map->alloc_flags);if (!wval)return -ENOMEM ;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH 2/4 regmap: cache: Use correct type of the rb_for_each() parameter
In reply to Andy ShevchenkoCompiler is not happy:
regcache.c:410:9: warning: Using plain integer as NULL pointer
Replace integer 0 by NULL.
--- drivers/base/regmap/regcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/regmap/regcache.c +1 -1
@@ -407,7 +407,7 @@ int regcache_sync(struct regmap *map)* have gone out of sync, force writes of all the paging * registers. */ -rb_for_each (node,0 , &map->range_tree, rbtree_all) { +rb_for_each (node,NULL , &map->range_tree, rbtree_all) {struct regmap_range_node *this = rb_entry(node, struct regmap_range_node, node);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH 3/4 regmap: cache: Switch to use kmemdup_array()
In reply to Andy ShevchenkoLet the kememdup_array() take care about multiplication and possible overflows.
--- drivers/base/regmap/regcache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/base/regmap/regcache.c +2 -2
@@ -170,8 +170,8 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)* a copy of it. */ if (config->reg_defaults) { - tmp_buf =kmemdup (config->reg_defaults, map->num_reg_defaults * -sizeof (struct reg_default ),GFP_KERNEL ); + tmp_buf =kmemdup_array (config->reg_defaults, map->num_reg_defaults, +sizeof (*map->reg_defaults),GFP_KERNEL );if (!tmp_buf)return -ENOMEM ; map->reg_defaults = tmp_buf;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH 4/4 regmap: maple: Switch to use kmemdup_array()
In reply to Andy ShevchenkoLet the kememdup_array() take care about multiplication and possible overflows.
--- drivers/base/regmap/regcache-maple.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/base/regmap/regcache-maple.c +6 -7
@@ -132,9 +132,9 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min, lower_index = mas.index; lower_last = min -1 ; - lower =kmemdup (entry, ((min - mas.index) * -sizeof (unsigned long )), - map->alloc_flags); + lower =kmemdup_array (entry, + min - mas.index,sizeof (*lower), + map->alloc_flags);if (!lower) { ret = -ENOMEM ; goto out_unlocked;
@@ -145,10 +145,9 @@ static int regcache_maple_drop(struct regmap *map, unsigned int min, upper_index = max +1 ; upper_last = mas.last; - upper =kmemdup (&entry[max - mas.index +1 ], - ((mas.last - max) * -sizeof (unsigned long )), - map->alloc_flags); + upper =kmemdup_array (&entry[max - mas.index +1 ], + mas.last - max,sizeof (*upper), + map->alloc_flags);if (!upper) { ret = -ENOMEM ; goto out_unlocked;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Mark Brown
maintainerQuoted 5 lines · Andy Shevchenko
Replace open coded
kmemdup_array(), which does an additional overflow check.While at it, fix one minor issue in
regcache.c.
Quoted 7 lines
Andy Shevchenko (4):
regmap: Switch to usekmemdup_array()
regmap: cache: Use correct type of therb_for_each()parameter
regmap: cache: Switch to usekmemdup_array()
regmap: maple: Switch to usekmemdup_array()[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next
Thanks!
[1/4] regmap: Switch to use kmemdup_array()
commit: 540c53d158d947db1249614d47437c660ba0b959
[2/4] regmap: cache: Use correct type of the rb_for_each() parameter
commit: 354662dc66f264b26c3e094162e0fad8715d009f
[3/4] regmap: cache: Switch to use kmemdup_array()
commit: f755d6955338bc704168629f70b380658a4918df
[4/4] regmap: maple: Switch to use kmemdup_array()
commit: bce843065804f770ac469d32a3d455b9a997b55fAll 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