dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Haoxiang Li" <haoxiang_li2024@163.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] accel/qaic: Free the DBC buffer on management transfer errors
Date: Sat, 28 Nov 2026 09:44:26 +0000	[thread overview]
Message-ID: <sashiko-outbox-238596@kernel.org> (raw)
In-Reply-To: <20261128093322.1217738-1-haoxiang_li2024@163.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] accel/qaic: memory leak in encode_activate() [1]
--

commit 48133c97c10bb67d1f23799c52aaf49134fd456e
Author: Haoxiang Li <haoxiang_li2024@163.com>

accel/qaic: Free the DBC buffer on management transfer errors

This commit frees the DBC buffer allocated during message encoding when
a management transfer fails in qaic_manage_msg_xfer().

> diff --git a/drivers/accel/qaic/qaic_control.c b/drivers/accel/qaic/qaic_control.c
> index 2ccc55486aac0..f322887ec53e8 100644
> --- a/drivers/accel/qaic/qaic_control.c
> +++ b/drivers/accel/qaic/qaic_control.c
> @@ -1250,6 +1250,8 @@ static int qaic_manage_msg_xfer(struct qaic_device *qdev, struct qaic_user *usr,
>  
>  lock_failed:
>  	free_dma_xfers(qdev, resources);
> +	if (ret)
> +		free_dbc_buf(qdev, resources);
>  encode_failed:
>  	spin_lock(&wrappers->lock);
>  	list_for_each_entry_safe(wrapper, w, &wrappers->list, list)

[Severity: High]
This problem wasn't introduced by this patch, but can encode_activate()
leak the DMA buffer in resources->buf [1] when a management message
contains more than one QAIC_TRANS_ACTIVATE_FROM_USR transaction?

encode_message() loops over user_msg->count transactions and calls
encode_activate() for each QAIC_TRANS_ACTIVATE_FROM_USR entry.  Each call
allocates a coherent DMA buffer and overwrites resources->buf and
resources->dma_addr without checking whether a buffer was already
allocated for an earlier transaction in the same ioctl:

drivers/accel/qaic/qaic_control.c:encode_activate() {
	...
	buf = dma_alloc_coherent(&qdev->pdev->dev, size, &dma_addr, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
	...
	resources->buf = buf;
	resources->dma_addr = dma_addr;
	...
}

Any earlier allocation in the same message is lost and cannot be freed by
free_dbc_buf(), allowing userspace to exhaust coherent DMA memory.

[1] https://sashiko.dev/#/bug/linux-ad70f5f2-e579-4654-84f6-691a5c89ecc1

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128093322.1217738-1-haoxiang_li2024@163.com?part=1

      reply	other threads:[~2026-11-28  9:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  9:33 [PATCH] accel/qaic: Free the DBC buffer on management transfer errors Haoxiang Li
2026-11-28  9:44 ` sashiko-bot [this message]

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=sashiko-outbox-238596@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=haoxiang_li2024@163.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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