diff mbox series

[v3] platform/chrome: chromeos_laptop: Use kmemdup_array instead of kmemdup for multiple allocation

Message ID 20240823024056.3031644-1-yujiaoliang@vivo.com (mailing list archive)
State Accepted
Commit d1b35e6d34e9b46fbf98444dd7aa114c032e9ac0
Headers show
Series [v3] platform/chrome: chromeos_laptop: Use kmemdup_array instead of kmemdup for multiple allocation | expand

Commit Message

Yu Jiaoliang Aug. 23, 2024, 2:40 a.m. UTC
Let the kememdup_array() take care about multiplication and possible
overflows.

Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
---
v2:
- Use sizeof(*i2c_peripherals) instead of sizeof(*src->i2c_peripherals)
- Format code
v3:
- Fix R-b tag
- Move this information below ---
---
 drivers/platform/chrome/chromeos_laptop.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Tzung-Bi Shih Aug. 23, 2024, 1:52 p.m. UTC | #1
On Fri, Aug 23, 2024 at 10:40:56AM +0800, Yu Jiaoliang wrote:
> Let the kememdup_array() take care about multiplication and possible
> overflows.
> 
> [...]

Applied to

    https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next

Thanks!

[1/1] platform/chrome: chromeos_laptop: Use kmemdup_array
      commit: d1b35e6d34e9b46fbf98444dd7aa114c032e9ac0
diff mbox series

Patch

diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
index a2cdbfbaeae6..3ab668764383 100644
--- a/drivers/platform/chrome/chromeos_laptop.c
+++ b/drivers/platform/chrome/chromeos_laptop.c
@@ -749,10 +749,9 @@  chromeos_laptop_prepare_i2c_peripherals(struct chromeos_laptop *cros_laptop,
 	if (!src->num_i2c_peripherals)
 		return 0;
 
-	i2c_peripherals = kmemdup(src->i2c_peripherals,
-					      src->num_i2c_peripherals *
-					  sizeof(*src->i2c_peripherals),
-					  GFP_KERNEL);
+	i2c_peripherals = kmemdup_array(src->i2c_peripherals,
+					src->num_i2c_peripherals,
+					sizeof(*i2c_peripherals), GFP_KERNEL);
 	if (!i2c_peripherals)
 		return -ENOMEM;