iwlwifi: mvm: fix possible memory leak
authorEytan Lifshitz <eytan.lifshitz@intel.com>
Wed, 18 Dec 2013 21:05:06 +0000 (23:05 +0200)
committerEmmanuel Grumbach <emmanuel.grumbach@intel.com>
Tue, 31 Dec 2013 17:03:43 +0000 (19:03 +0200)
In case of invalid section_id, the function returns after
it aleready allocated memory. Fixed by change the order of actions.

Signed-off-by: Eytan Lifshitz <eytan.lifshitz@intel.com>
Reviewed-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
drivers/net/wireless/iwlwifi/mvm/nvm.c

index 48089b1625fff7c1dfc804c6f84a9e68ae56d282..c03406fc27ff60507892ce2a330f2e384ad23c7f 100644 (file)
@@ -367,16 +367,17 @@ static int iwl_mvm_read_external_nvm(struct iwl_mvm *mvm)
                        break;
                }
 
+               if (WARN(section_id >= NVM_NUM_OF_SECTIONS,
+                        "Invalid NVM section ID %d\n", section_id)) {
+                       ret = -EINVAL;
+                       break;
+               }
+
                temp = kmemdup(file_sec->data, section_size, GFP_KERNEL);
                if (!temp) {
                        ret = -ENOMEM;
                        break;
                }
-               if (WARN_ON(section_id >= NVM_NUM_OF_SECTIONS)) {
-                       IWL_ERR(mvm, "Invalid NVM section ID\n");
-                       ret = -EINVAL;
-                       break;
-               }
                mvm->nvm_sections[section_id].data = temp;
                mvm->nvm_sections[section_id].length = section_size;