diff mbox series

[v1] net: wireless: Use kmemdup_array instead of kmemdup for multiple allocation

Message ID 20240821072410.4065645-1-yujiaoliang@vivo.com (mailing list archive)
State Changes Requested
Delegated to: Johannes Berg
Headers show
Series [v1] net: wireless: Use kmemdup_array instead of kmemdup for multiple allocation | expand

Commit Message

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

Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
---
 net/wireless/util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Christophe JAILLET Aug. 21, 2024, 9:38 a.m. UTC | #1
Le 21/08/2024 à 09:24, Yu Jiaoliang a écrit :
> Let the kememdup_array() take care about multiplication and possible
> overflows.
> 
> Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
> ---
>   net/wireless/util.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/wireless/util.c b/net/wireless/util.c
> index 9a7c3adc8a3b..6cf19dda5d2a 100644
> --- a/net/wireless/util.c
> +++ b/net/wireless/util.c
> @@ -2435,8 +2435,8 @@ int cfg80211_iter_combinations(struct wiphy *wiphy,
>   		if (params->num_different_channels > c->num_different_channels)
>   			continue;
>   
> -		limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits,
> -				 GFP_KERNEL);
> +		limits = kmemdup_array(c->limits, c->n_limits, sizeof(limits[0]),

Maybe sizeof(*limits) would be a more usual pattern?

CJ

> +				       GFP_KERNEL);
>   		if (!limits)
>   			return -ENOMEM;
>
Kalle Valo Aug. 21, 2024, 10:05 a.m. UTC | #2
Yu Jiaoliang <yujiaoliang@vivo.com> writes:

> Let the kememdup_array() take care about multiplication and possible
> overflows.
>
> Signed-off-by: Yu Jiaoliang <yujiaoliang@vivo.com>
> ---
>  net/wireless/util.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

The title prefix should be "wifi: cfg80211:".
diff mbox series

Patch

diff --git a/net/wireless/util.c b/net/wireless/util.c
index 9a7c3adc8a3b..6cf19dda5d2a 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -2435,8 +2435,8 @@  int cfg80211_iter_combinations(struct wiphy *wiphy,
 		if (params->num_different_channels > c->num_different_channels)
 			continue;
 
-		limits = kmemdup(c->limits, sizeof(limits[0]) * c->n_limits,
-				 GFP_KERNEL);
+		limits = kmemdup_array(c->limits, c->n_limits, sizeof(limits[0]),
+				       GFP_KERNEL);
 		if (!limits)
 			return -ENOMEM;