dma-mapping: clear dev->dma_mem to NULL after freeing it

JIRA: https://issues.redhat.com/browse/RHEL-28780
Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit b07bc2347672cc8c7293c64499f1488278c5ca3d
Author: Joakim Zhang <joakim.zhang@cixtech.com>
Date:   Thu Dec 14 16:25:26 2023 +0800

    dma-mapping: clear dev->dma_mem to NULL after freeing it

    Reproduced with below sequence:
    dma_declare_coherent_memory()->dma_release_coherent_memory()
    ->dma_declare_coherent_memory()->"return -EBUSY" error

    It will return -EBUSY from the dma_assign_coherent_memory()
    in dma_declare_coherent_memory(), the reason is that dev->dma_mem
    pointer has not been set to NULL after it's freed.

    Fixes: cf65a0f6f6 ("dma-mapping: move all DMA mapping code to kernel/dma")
    Signed-off-by: Joakim Zhang <joakim.zhang@cixtech.com>
    Signed-off-by: Christoph Hellwig <hch@lst.de>

(cherry picked from commit b07bc2347672cc8c7293c64499f1488278c5ca3d)
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
This commit is contained in:
Jerry Snitselaar 2023-12-14 16:25:26 +08:00
parent cfcd8edd97
commit 9b56f95b9d
1 changed files with 3 additions and 1 deletions

View File

@ -132,8 +132,10 @@ int dma_declare_coherent_memory(struct device *dev, phys_addr_t phys_addr,
void dma_release_coherent_memory(struct device *dev)
{
if (dev)
if (dev) {
_dma_release_coherent_memory(dev->dma_mem);
dev->dma_mem = NULL;
}
}
static void *__dma_alloc_from_coherent(struct device *dev,