From: Lizhi Hou <lizhi.hou@amd.com>
To: <christian.koenig@amd.com>, <sumit.semwal@linaro.org>,
<phasta@kernel.org>, <linaro-mm-sig@lists.linaro.org>,
<linux-media@vger.kernel.org>
Cc: Lizhi Hou <lizhi.hou@amd.com>, <dri-devel@lists.freedesktop.org>,
<linux-kernel@vger.kernel.org>, <max.zhen@amd.com>,
<sonal.santan@amd.com>
Subject: [PATCH V1] dma-buf: Reject attaching a zero-sized dma-buf
Date: Mon, 23 Nov 2026 09:11:14 -0800 [thread overview]
Message-ID: <20261123171114.1451429-1-lizhi.hou@amd.com> (raw)
Attaching to a zero-sized dma-buf does not make sense at all: there is
nothing for an importer to map.
So reject the attach, using WARN_ON() because a zero-sized dma-buf is
an exporter bug that userspace cannot trigger on its own.
Adding the check to dma_buf_export() instead was considered, which
would prevent zero-sized DMA-bufs from being created in the first
place. It is not done here because drivers may be using zero-sized
DMA-bufs for driver internal buffers, and refusing them at creation
time risks regressing those users.
Fixes: d15bd7ee445d ("dma-buf: Introduce dma buffer sharing mechanism")
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
drivers/dma-buf/dma-buf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c
index 5c6957f8839a..8be7b6023e4a 100644
--- a/drivers/dma-buf/dma-buf.c
+++ b/drivers/dma-buf/dma-buf.c
@@ -1050,6 +1050,9 @@ dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
if (WARN_ON(!dmabuf || !dev))
return ERR_PTR(-EINVAL);
+ if (WARN_ON(!dmabuf->size))
+ return ERR_PTR(-EINVAL);
+
attach = kzalloc_obj(*attach);
if (!attach)
return ERR_PTR(-ENOMEM);
--
2.34.1
reply other threads:[~2026-11-23 17:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261123171114.1451429-1-lizhi.hou@amd.com \
--to=lizhi.hou@amd.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=max.zhen@amd.com \
--cc=phasta@kernel.org \
--cc=sonal.santan@amd.com \
--cc=sumit.semwal@linaro.org \
/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®