Skip to contentSkip to conversation

iwlwifi: d3: Use struct_size() helper

PATCH In review Gustavo A. R. Silva 2 participants 3 messages Apr 3, 2019 – May 14, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iwlwifi: d3: Use struct_size() helper

Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used.

So, change the following form:

sizeof(*pattern_cmd) +

               wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern)

to :

struct_size(pattern_cmd, patterns, wowlan->n_patterns)

This code was detected with the help of Coccinelle.

---
 drivers/net/wireless/intel/iwlwifi/mvm/d3.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/d3.c +1 -2
index 83fd7f93d9f5..99589b910bce 100644
@@ -398,8 +398,7 @@ static int iwl_mvm_send_patterns(struct iwl_mvm *mvm,
 	if (!wowlan->n_patterns)
 		return 0;
 
-	cmd.len[0] = sizeof(*pattern_cmd) +
-		wowlan->n_patterns * sizeof(struct iwl_wowlan_pattern);
+	cmd.len[0] = struct_size(pattern_cmd, patterns, wowlan->n_patterns);
 
 	pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
 	if (!pattern_cmd)
Signature · 1 line
2.21.0
#1 lore raw
Quoted 36 lines · Gustavo A. R. Silva

Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used.

So, change the following form:

sizeof(*pattern_cmd) +

               wowlan->n_patterns * sizeof(struct

iwlagn_wowlan_pattern)

to :

struct_size(pattern_cmd, patterns, wowlan->n_patterns)

This code was detected with the help of Coccinelle.

---
 drivers/net/wireless/intel/iwlwifi/mvm/d3.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/d3.c +1 -2
index 83fd7f93d9f5..99589b910bce 100644
@@ -398,8 +398,7 @@ static int iwl_mvm_send_patterns(struct iwl_mvm
 *mvm,
 	if (!wowlan->n_patterns)
 		return 0;
 
-	cmd.len[0] = sizeof(*pattern_cmd) +
-		wowlan->n_patterns * sizeof(struct iwl_wowlan_pattern);
+	cmd.len[0] = struct_size(pattern_cmd, patterns, wowlan-
 >n_patterns);
 

drivers/net/wireless/intel/iwlwifi/mvm/d3.c static int iwl_mvm_send_patterns(struct iwl_mvm *mvm, · line 404

Quoted 2 lines
drivers/net/wireless/intel/iwlwifi/mvm/d3.c +0 -0
 	pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
 	if (!pattern_cmd)

Thanks! Applied to our internal tree and it will reach the mainline following our normal upstreaming process.

--
Cheers,
Luca.

#2 lore raw
Quoted 4 lines · Luciano Coelho

Thanks! Applied to our internal tree and it will reach the mainline following our normal upstreaming process.

Awesome. :)

Thanks, Luciano.
--
Gustavo