iwlwifi: lib: Use struct_size() helper
authorGustavo A. R. Silva <gustavo@embeddedor.com>
Wed, 3 Apr 2019 15:59:01 +0000 (10:59 -0500)
committerLuca Coelho <luciano.coelho@intel.com>
Sat, 29 Jun 2019 07:09:38 +0000 (10:09 +0300)
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.

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: Luca Coelho <luciano.coelho@intel.com>
drivers/net/wireless/intel/iwlwifi/dvm/lib.c

index 1fd6bf5..eab94d2 100644 (file)
@@ -1009,8 +1009,7 @@ int iwlagn_send_patterns(struct iwl_priv *priv,
        if (!wowlan->n_patterns)
                return 0;
 
-       cmd.len[0] = sizeof(*pattern_cmd) +
-               wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern);
+       cmd.len[0] = struct_size(pattern_cmd, patterns, wowlan->n_patterns);
 
        pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
        if (!pattern_cmd)