Re: [PATCH v1] wifi: mac80211: use kmemdup_array instead of kmemdup for multiple allocation
From: Michal Swiatkowski
Date: Tue Aug 27 2024 - 02:57:56 EST
On Tue, Aug 27, 2024 at 11:56:52AM +0800, Shen Lichuan wrote:
> Let the kmemdup_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@xxxxxxxx>
> ---
> net/mac80211/main.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/net/mac80211/main.c b/net/mac80211/main.c
> index a3104b6ea6f0..f16ebad36a83 100644
> --- a/net/mac80211/main.c
> +++ b/net/mac80211/main.c
> @@ -1051,9 +1051,9 @@ static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
> return 0;
>
> /* Driver provides cipher suites, but we need to exclude WEP */
> - suites = kmemdup(local->hw.wiphy->cipher_suites,
> - sizeof(u32) * local->hw.wiphy->n_cipher_suites,
> - GFP_KERNEL);
> + suites = kmemdup_array(local->hw.wiphy->cipher_suites,
> + local->hw.wiphy->n_cipher_suites, sizeof(u32),
You can move sizeof(u32) to the next line to not exceed 80 lines.
> + GFP_KERNEL);
> if (!suites)
> return -ENOMEM;
>
Otherwise:
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@xxxxxxxxxxxxxxx>
Thanks,
Michal
> --
> 2.17.1
>