rsi: Fix possible leak when loading firmware

Commit 5d5cd85ff4 ("rsi: Fix failure to load firmware after memory
leak fix and fix the leak") also added a check on the allocation of
DMA-accessible memory that may directly return. In that case the
already allocated firmware data is leaked. Make sure the data is
always freed correctly. Detected by Coverity CID 1316519.

Fixes: 5d5cd85ff4 ("rsi: Fix failure to load firmware after memory leak fix and fix the leak")
Signed-off-by: Christian Engelmayer <cengelma@gmx.at>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
This commit is contained in:
Christian Engelmayer 2015-08-21 23:14:26 +02:00 committed by Kalle Valo
parent 4e70f2144d
commit a8b9774571
2 changed files with 12 additions and 4 deletions

View File

@ -203,8 +203,10 @@ static int rsi_load_ta_instructions(struct rsi_common *common)
/* Copy firmware into DMA-accessible memory */ /* Copy firmware into DMA-accessible memory */
fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL); fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
if (!fw) if (!fw) {
return -ENOMEM; status = -ENOMEM;
goto out;
}
len = fw_entry->size; len = fw_entry->size;
if (len % 4) if (len % 4)
@ -217,6 +219,8 @@ static int rsi_load_ta_instructions(struct rsi_common *common)
status = rsi_copy_to_card(common, fw, len, num_blocks); status = rsi_copy_to_card(common, fw, len, num_blocks);
kfree(fw); kfree(fw);
out:
release_firmware(fw_entry); release_firmware(fw_entry);
return status; return status;
} }

View File

@ -148,8 +148,10 @@ static int rsi_load_ta_instructions(struct rsi_common *common)
/* Copy firmware into DMA-accessible memory */ /* Copy firmware into DMA-accessible memory */
fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL); fw = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
if (!fw) if (!fw) {
return -ENOMEM; status = -ENOMEM;
goto out;
}
len = fw_entry->size; len = fw_entry->size;
if (len % 4) if (len % 4)
@ -162,6 +164,8 @@ static int rsi_load_ta_instructions(struct rsi_common *common)
status = rsi_copy_to_card(common, fw, len, num_blocks); status = rsi_copy_to_card(common, fw, len, num_blocks);
kfree(fw); kfree(fw);
out:
release_firmware(fw_entry); release_firmware(fw_entry);
return status; return status;
} }