From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Haotian Zhang <vulab@iscas.ac.cn>,
tfiga@chromium.org, Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil@kernel.org>
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] media: videobuf2: Fix device reference leak in vb2_dc_alloc error path
Date: Tue, 28 Oct 2025 08:10:01 +0100 [thread overview]
Message-ID: <aaac0d2b-ec3f-4469-9334-a7216b85b33f@samsung.com> (raw)
In-Reply-To: <20251028064443.655-1-vulab@iscas.ac.cn>
On 28.10.2025 07:44, Haotian Zhang wrote:
> In vb2_dc_alloc(), get_device() is called to increment the device
> reference count. However, if subsequent DMA allocation fails
> (vb2_dc_alloc_coherent or vb2_dc_alloc_non_coherent returns error),
> the function returns without calling put_device(), causing a device
> reference leak.
>
> Add put_device() call in the error path before kfree() to properly
> release the device reference acquired earlier.
>
> Fixes: de27891f675e ("media: videobuf2: handle non-contiguous DMA allocations")
> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
> drivers/media/common/videobuf2/videobuf2-dma-contig.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> index a13ec569c82f..7123c5fae92c 100644
> --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c
> @@ -258,6 +258,7 @@ static void *vb2_dc_alloc(struct vb2_buffer *vb,
>
> if (ret) {
> dev_err(dev, "dma alloc of size %lu failed\n", size);
> + put_device(buf->dev);
> kfree(buf);
> return ERR_PTR(-ENOMEM);
> }
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
prev parent reply other threads:[~2025-10-28 7:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20251028064507eucas1p2895db44758261941ca898cb4edd2c7b3@eucas1p2.samsung.com>
2025-10-28 6:44 ` Haotian Zhang
2025-10-28 7:10 ` Marek Szyprowski [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=aaac0d2b-ec3f-4469-9334-a7216b85b33f@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=hverkuil@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=tfiga@chromium.org \
--cc=vulab@iscas.ac.cn \
/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®