diff mbox series

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

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

Commit Message

Yu Jiaoliang Aug. 21, 2024, 8:41 a.m. UTC
Let the kememdup_array() take care about multiplication and possible
overflows.

Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
---
 drivers/platform/chrome/chromeos_laptop.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Christophe JAILLET Aug. 21, 2024, 10:43 a.m. UTC | #1
Le 21/08/2024 à 10:41, Yu Jiaoliang a écrit :
> Let the kememdup_array() take care about multiplication and possible
> overflows.
> 
> Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
> ---
>   drivers/platform/chrome/chromeos_laptop.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
> index a2cdbfbaeae6..7bedd82dd3a5 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(*src->i2c_peripherals), GFP_KERNEL);
>   	if (!i2c_peripherals)
>   		return -ENOMEM;
>   

Nitpick: sizeof(*i2c_peripherals) would also work and is slightly less 
verbose.

CJ
diff mbox series

Patch

diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
index a2cdbfbaeae6..7bedd82dd3a5 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(*src->i2c_peripherals), GFP_KERNEL);
 	if (!i2c_peripherals)
 		return -ENOMEM;