From: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
To: Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
Jeff Johnson <jjohnson@kernel.org>
Cc: iommu@lists.linux.dev,
"linux-kernel@vger.kernel.org >> linux-kernel"
<linux-kernel@vger.kernel.org>,
"ath11k@lists.infradead.org" <ath11k@lists.infradead.org>
Subject: is dma_mapping_error() check necessary for dma_alloc_noncoherent()?
Date: Tue, 26 Aug 2025 17:44:42 +0800 [thread overview]
Message-ID: <ff6c1fe6-820f-4e58-8395-df06aa91706c@oss.qualcomm.com> (raw)
Hi guys,
I have a driver which allocate noncoherent DMA buffer and get the returned CPU addr tested:
vaddr_unaligned = dma_alloc_noncoherent(ab->dev, rx_tid->unaligned_size, &paddr,
DMA_BIDIRECTIONAL, GFP_ATOMIC);
if (!vaddr_unaligned) {
spin_unlock_bh(&ab->base_lock);
return -ENOMEM;
}
while free the buffer
dma_free_noncoherent(ab->dev, rx_tid->unaligned_size,
rx_tid->vaddr_unaligned,
rx_tid->paddr_unaligned, DMA_BIDIRECTIONAL);
I get below warnings:
DMA-API: ath11k_pci 0000:03:00.0: device driver failed to check map error[device
address=0x00000000f3ad7000] [size=639 bytes] [mapped as single]
WARNING: CPU: 15 PID: 64303 at kernel/dma/debug.c:1036 check_unmap+0x7e2/0x950
RIP: 0010:check_unmap+0x7e2/0x950
Call Trace:
<TASK>
? free_to_partial_list+0x9d/0x350
debug_dma_unmap_page+0xac/0xc0
? debug_smp_processor_id+0x17/0x20
? rcu_is_watching+0x13/0x70
dma_free_pages+0x56/0x180
[...]
</TASK>
---[ end trace 0000000000000000 ]---
DMA-API: Mapped at:
debug_dma_map_page+0x7c/0x140
dma_alloc_pages+0x74/0x220
[...]
Checking code gives me the impression that I should do dma_mapping_error() check as well.
And indeed with below diff the warning is gone:
+ dma_mapping_error(ab->dev, paddr);
However this does not make sense to me since IMO testing the CPU address is good enough, I
can not imagine a valid case where DMA alloc/map fails while returning a valid CPU
address, no?
If I was right, should we remove invocation to debug_dma_map_page() in dma_alloc_pages()?
next reply other threads:[~2025-08-26 9:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20250826094453eucas1p178ff4a39db0c655f3505128a5cfb0a6a@eucas1p1.samsung.com>
2025-08-26 9:44 ` Baochen Qiang [this message]
2025-08-26 14:09 ` Marek Szyprowski
2025-08-27 1:55 ` Baochen Qiang
2025-08-27 7:31 ` Christoph Hellwig
2025-08-28 6:32 ` Baochen Qiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ff6c1fe6-820f-4e58-8395-df06aa91706c@oss.qualcomm.com \
--to=baochen.qiang@oss.qualcomm.com \
--cc=ath11k@lists.infradead.org \
--cc=iommu@lists.linux.dev \
--cc=jjohnson@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®