Commit baf5b752 authored by Corentin LABBE's avatar Corentin LABBE Committed by Herbert Xu

crypto: cavium - add release_firmware to all return case

Two return case misses to call release_firmware() and so leak some
memory.

This patch create a fw_release label (and so a common error path)
and use it on all return case.

Detected by CoverityScan, CID#1416422 ("Resource Leak")
Signed-off-by: default avatarCorentin Labbe <clabbe.montjoie@gmail.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 249cb063
...@@ -268,8 +268,10 @@ static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae) ...@@ -268,8 +268,10 @@ static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae)
mcode = &cpt->mcode[cpt->next_mc_idx]; mcode = &cpt->mcode[cpt->next_mc_idx];
memcpy(mcode->version, (u8 *)fw_entry->data, CPT_UCODE_VERSION_SZ); memcpy(mcode->version, (u8 *)fw_entry->data, CPT_UCODE_VERSION_SZ);
mcode->code_size = ntohl(ucode->code_length) * 2; mcode->code_size = ntohl(ucode->code_length) * 2;
if (!mcode->code_size) if (!mcode->code_size) {
return -EINVAL; ret = -EINVAL;
goto fw_release;
}
mcode->is_ae = is_ae; mcode->is_ae = is_ae;
mcode->core_mask = 0ULL; mcode->core_mask = 0ULL;
...@@ -280,7 +282,8 @@ static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae) ...@@ -280,7 +282,8 @@ static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae)
&mcode->phys_base, GFP_KERNEL); &mcode->phys_base, GFP_KERNEL);
if (!mcode->code) { if (!mcode->code) {
dev_err(dev, "Unable to allocate space for microcode"); dev_err(dev, "Unable to allocate space for microcode");
return -ENOMEM; ret = -ENOMEM;
goto fw_release;
} }
memcpy((void *)mcode->code, (void *)(fw_entry->data + sizeof(*ucode)), memcpy((void *)mcode->code, (void *)(fw_entry->data + sizeof(*ucode)),
...@@ -302,12 +305,14 @@ static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae) ...@@ -302,12 +305,14 @@ static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae)
ret = do_cpt_init(cpt, mcode); ret = do_cpt_init(cpt, mcode);
if (ret) { if (ret) {
dev_err(dev, "do_cpt_init failed with ret: %d\n", ret); dev_err(dev, "do_cpt_init failed with ret: %d\n", ret);
return ret; goto fw_release;
} }
dev_info(dev, "Microcode Loaded %s\n", mcode->version); dev_info(dev, "Microcode Loaded %s\n", mcode->version);
mcode->is_mc_valid = 1; mcode->is_mc_valid = 1;
cpt->next_mc_idx++; cpt->next_mc_idx++;
fw_release:
release_firmware(fw_entry); release_firmware(fw_entry);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment