diff mbox series

[v1] wifi: mac80211: use kmemdup_array instead of kmemdup for multiple allocation

Message ID 20240827035652.33558-1-shenlichuan@vivo.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [v1] wifi: mac80211: use kmemdup_array instead of kmemdup for multiple allocation | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 16 this patch: 16
netdev/checkpatch warning WARNING: line length of 85 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-08-27--06-00 (tests: 712)

Commit Message

Shen Lichuan Aug. 27, 2024, 3:56 a.m. UTC
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@vivo.com>
---
 net/mac80211/main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Michal Swiatkowski Aug. 27, 2024, 6:55 a.m. UTC | #1
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@vivo.com>
> ---
>  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@linux.intel.com>

Thanks,
Michal

> -- 
> 2.17.1
>
diff mbox series

Patch

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),
+				       GFP_KERNEL);
 		if (!suites)
 			return -ENOMEM;