]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: videobuf2: Fix device reference leak in vb2_dc_alloc error path
authorHaotian Zhang <vulab@iscas.ac.cn>
Tue, 28 Oct 2025 06:44:43 +0000 (14:44 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Jan 2026 09:14:46 +0000 (10:14 +0100)
commit 94de23a9aa487d7c1372efb161721d7949a177ae upstream.

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")
Cc: stable@vger.kernel.org
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Reviewed-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/common/videobuf2/videobuf2-dma-contig.c

index bb0b7fa67b539aa73ad5ccf3c3bc318e26f8a4cb..faad72f795450bbb11bf25214997927b08709522 100644 (file)
@@ -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);
        }