diff mbox series

[v1] drivers/pinctrl/samsung: Use kmemdup_array instead of kmemdup for multiple allocation

Message ID 20240823082407.48219-1-shenlichuan@vivo.com (mailing list archive)
State New
Headers show
Series [v1] drivers/pinctrl/samsung: Use kmemdup_array instead of kmemdup for multiple allocation | expand

Commit Message

Shen Lichuan Aug. 23, 2024, 8:24 a.m. UTC
Let the kememdup_array() take care about
multiplication and possible overflows.

Using kmemdup_array() is more appropriate 
and makes the code easier to audit.

Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
---
 drivers/pinctrl/samsung/pinctrl-samsung.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Krzysztof Kozlowski Aug. 23, 2024, 8:56 a.m. UTC | #1
On 23/08/2024 10:24, Shen Lichuan wrote:
> Let the kememdup_array() take care about
> multiplication and possible overflows.
> 
> Using kmemdup_array() is more appropriate 
> and makes the code easier to audit.

Please wrap commit message according to Linux coding style / submission
process (neither too early nor over the limit):
https://elixir.bootlin.com/linux/v6.4-rc1/source/Documentation/process/submitting-patches.rst#L597

> 
> Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
> ---
>  drivers/pinctrl/samsung/pinctrl-samsung.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
> index e4464ee815f9..da24890f27f7 100644
> --- a/drivers/pinctrl/samsung/pinctrl-samsung.c
> +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
> @@ -122,8 +122,8 @@ static int add_map_configs(struct device *dev, struct pinctrl_map **map,
>  	if (WARN_ON(*num_maps == *reserved_maps))
>  		return -ENOSPC;
>  
> -	dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
> -			      GFP_KERNEL);
> +	dup_configs = kmemdup_array(configs, num_configs,
> +					sizeof(*dup_configs), GFP_KERNEL);

Misaligned and wrapped too early.

>  

Best regards,
Krzysztof
diff mbox series

Patch

diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
index e4464ee815f9..da24890f27f7 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
@@ -122,8 +122,8 @@  static int add_map_configs(struct device *dev, struct pinctrl_map **map,
 	if (WARN_ON(*num_maps == *reserved_maps))
 		return -ENOSPC;
 
-	dup_configs = kmemdup(configs, num_configs * sizeof(*dup_configs),
-			      GFP_KERNEL);
+	dup_configs = kmemdup_array(configs, num_configs,
+					sizeof(*dup_configs), GFP_KERNEL);
 	if (!dup_configs)
 		return -ENOMEM;