2024-06-06 19:56:34

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 0/4] 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(-)

--
2.43.0.rc1.1336.g36b5255a03ac



2024-06-06 20:51:54

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 4/4] regmap: maple: Switch to use kmemdup_array()

Let the kememdup_array() take care about multiplication and possible
overflows.

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/base/regmap/regcache-maple.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/base/regmap/regcache-maple.c b/drivers/base/regmap/regcache-maple.c
index e42433404854..f0df2da6d522 100644
--- a/drivers/base/regmap/regcache-maple.c
+++ b/drivers/base/regmap/regcache-maple.c
@@ -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;
--
2.43.0.rc1.1336.g36b5255a03ac


2024-06-07 21:58:14

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v1 0/4] regmap: Switch to use kmemdup_array()

On Thu, 06 Jun 2024 19:46:21 +0300, Andy Shevchenko wrote:
> 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()
>
> [...]

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: bce843065804f770ac469d32a3d455b9a997b55f

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