diff options
author | Corentin LABBE <clabbe.montjoie@gmail.com> | 2017-08-14 07:58:54 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-08-22 02:54:54 -0400 |
commit | baf5b752dae2b7c84b3fa5ffb0eb41648d659c09 (patch) | |
tree | 166397fd293adee793366fbbd1177978fdd5ebe7 | |
parent | 249cb0632570302e2c61f900806b92f3fe66783b (diff) |
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: Corentin Labbe <clabbe.montjoie@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | drivers/crypto/cavium/cpt/cptpf_main.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/drivers/crypto/cavium/cpt/cptpf_main.c b/drivers/crypto/cavium/cpt/cptpf_main.c index 4119c40e7c4b..34a6d8bf229e 100644 --- a/drivers/crypto/cavium/cpt/cptpf_main.c +++ b/drivers/crypto/cavium/cpt/cptpf_main.c | |||
@@ -268,8 +268,10 @@ static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae) | |||
268 | mcode = &cpt->mcode[cpt->next_mc_idx]; | 268 | mcode = &cpt->mcode[cpt->next_mc_idx]; |
269 | memcpy(mcode->version, (u8 *)fw_entry->data, CPT_UCODE_VERSION_SZ); | 269 | memcpy(mcode->version, (u8 *)fw_entry->data, CPT_UCODE_VERSION_SZ); |
270 | mcode->code_size = ntohl(ucode->code_length) * 2; | 270 | mcode->code_size = ntohl(ucode->code_length) * 2; |
271 | if (!mcode->code_size) | 271 | if (!mcode->code_size) { |
272 | return -EINVAL; | 272 | ret = -EINVAL; |
273 | goto fw_release; | ||
274 | } | ||
273 | 275 | ||
274 | mcode->is_ae = is_ae; | 276 | mcode->is_ae = is_ae; |
275 | mcode->core_mask = 0ULL; | 277 | 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 | &mcode->phys_base, GFP_KERNEL); | 282 | &mcode->phys_base, GFP_KERNEL); |
281 | if (!mcode->code) { | 283 | if (!mcode->code) { |
282 | dev_err(dev, "Unable to allocate space for microcode"); | 284 | dev_err(dev, "Unable to allocate space for microcode"); |
283 | return -ENOMEM; | 285 | ret = -ENOMEM; |
286 | goto fw_release; | ||
284 | } | 287 | } |
285 | 288 | ||
286 | memcpy((void *)mcode->code, (void *)(fw_entry->data + sizeof(*ucode)), | 289 | 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 | ret = do_cpt_init(cpt, mcode); | 305 | ret = do_cpt_init(cpt, mcode); |
303 | if (ret) { | 306 | if (ret) { |
304 | dev_err(dev, "do_cpt_init failed with ret: %d\n", ret); | 307 | dev_err(dev, "do_cpt_init failed with ret: %d\n", ret); |
305 | return ret; | 308 | goto fw_release; |
306 | } | 309 | } |
307 | 310 | ||
308 | dev_info(dev, "Microcode Loaded %s\n", mcode->version); | 311 | dev_info(dev, "Microcode Loaded %s\n", mcode->version); |
309 | mcode->is_mc_valid = 1; | 312 | mcode->is_mc_valid = 1; |
310 | cpt->next_mc_idx++; | 313 | cpt->next_mc_idx++; |
314 | |||
315 | fw_release: | ||
311 | release_firmware(fw_entry); | 316 | release_firmware(fw_entry); |
312 | 317 | ||
313 | return ret; | 318 | return ret; |