Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: videobuf2: Fix device reference leak in vb2_dc_alloc error path

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>

authored by

Haotian Zhang and committed by
Hans Verkuil
94de23a9 ba92a96b

+1
+1
drivers/media/common/videobuf2/videobuf2-dma-contig.c
··· 258 258 259 259 if (ret) { 260 260 dev_err(dev, "dma alloc of size %lu failed\n", size); 261 + put_device(buf->dev); 261 262 kfree(buf); 262 263 return ERR_PTR(-ENOMEM); 263 264 }