Skip to content

Commit d07e9fa

Browse files
AlamyLiustorulf
authored andcommitted
mmc: cqhci: Fix a tiny potential memory leak on error condition
Free up the allocated memory in the case of error return The value of mmc_host->cqe_enabled stays 'false'. Thus, cqhci_disable (mmc_cqe_ops->cqe_disable) won't be called to free the memory. Also, cqhci_disable() seems to be designed to disable and free all resources, not suitable to handle this corner case. Fixes: a408022 ("mmc: cqhci: support for command queue enabled host") Signed-off-by: Alamy Liu <alamy.liu@gmail.com> Acked-by: Adrian Hunter <adrian.hunter@intel.com> Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 27ec9dc commit d07e9fa

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/mmc/host/cqhci.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,21 @@ static int cqhci_host_alloc_tdl(struct cqhci_host *cq_host)
217217
cq_host->desc_size,
218218
&cq_host->desc_dma_base,
219219
GFP_KERNEL);
220+
if (!cq_host->desc_base)
221+
return -ENOMEM;
222+
220223
cq_host->trans_desc_base = dmam_alloc_coherent(mmc_dev(cq_host->mmc),
221224
cq_host->data_size,
222225
&cq_host->trans_desc_dma_base,
223226
GFP_KERNEL);
224-
if (!cq_host->desc_base || !cq_host->trans_desc_base)
227+
if (!cq_host->trans_desc_base) {
228+
dmam_free_coherent(mmc_dev(cq_host->mmc), cq_host->desc_size,
229+
cq_host->desc_base,
230+
cq_host->desc_dma_base);
231+
cq_host->desc_base = NULL;
232+
cq_host->desc_dma_base = 0;
225233
return -ENOMEM;
234+
}
226235

227236
pr_debug("%s: cqhci: desc-base: 0x%p trans-base: 0x%p\n desc_dma 0x%llx trans_dma: 0x%llx\n",
228237
mmc_hostname(cq_host->mmc), cq_host->desc_base, cq_host->trans_desc_base,

0 commit comments

Comments
 (0)