aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/intel
diff options
context:
space:
mode:
authorGustavo A. R. Silva <gustavo@embeddedor.com>2019-01-08 12:55:19 -0500
committerLuca Coelho <luciano.coelho@intel.com>2019-02-20 13:47:55 -0500
commit6b367c9f88b0813f6a557e688b665324499a159e (patch)
tree4aee1b1b8660f2238078d16a53f711303091ff48 /drivers/net/wireless/intel
parent9178aa7c465440bae84a0de002d919ad7034a08a (diff)
iwlwifi: nvm-parse: use struct_size() in kzalloc()
One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example: struct foo { int stuff; void *entry[]; }; instance = kzalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL); Instead of leaving these open-coded and prone to type mistakes, we can now use the new struct_size() helper: instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL); 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>
Diffstat (limited to 'drivers/net/wireless/intel')
-rw-r--r--drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
index 503860a2b36d..ca6a243d704b 100644
--- a/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
+++ b/drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c
@@ -946,15 +946,13 @@ iwl_parse_nvm_data(struct iwl_trans *trans, const struct iwl_cfg *cfg,
946 const __le16 *ch_section; 946 const __le16 *ch_section;
947 947
948 if (cfg->nvm_type != IWL_NVM_EXT) 948 if (cfg->nvm_type != IWL_NVM_EXT)
949 data = kzalloc(sizeof(*data) + 949 data = kzalloc(struct_size(data, channels,
950 sizeof(struct ieee80211_channel) * 950 IWL_NVM_NUM_CHANNELS),
951 IWL_NVM_NUM_CHANNELS, 951 GFP_KERNEL);
952 GFP_KERNEL);
953 else 952 else
954 data = kzalloc(sizeof(*data) + 953 data = kzalloc(struct_size(data, channels,
955 sizeof(struct ieee80211_channel) * 954 IWL_NVM_NUM_CHANNELS_EXT),
956 IWL_NVM_NUM_CHANNELS_EXT, 955 GFP_KERNEL);
957 GFP_KERNEL);
958 if (!data) 956 if (!data)
959 return NULL; 957 return NULL;
960 958
@@ -1441,9 +1439,7 @@ struct iwl_nvm_data *iwl_get_nvm(struct iwl_trans *trans,
1441 if (empty_otp) 1439 if (empty_otp)
1442 IWL_INFO(trans, "OTP is empty\n"); 1440 IWL_INFO(trans, "OTP is empty\n");
1443 1441
1444 nvm = kzalloc(sizeof(*nvm) + 1442 nvm = kzalloc(struct_size(nvm, channels, IWL_NUM_CHANNELS), GFP_KERNEL);
1445 sizeof(struct ieee80211_channel) * IWL_NUM_CHANNELS,
1446 GFP_KERNEL);
1447 if (!nvm) { 1443 if (!nvm) {
1448 ret = -ENOMEM; 1444 ret = -ENOMEM;
1449 goto out; 1445 goto out;