Skip to content

Commit 0d96687

Browse files
tombamchehab
authored andcommitted
media: videobuf2-dma-contig: fix bad kfree in vb2_dma_contig_clear_max_seg_size
Commit 9495b7e ("driver core: platform: Initialize dma_parms for platform devices") in v5.7-rc5 causes vb2_dma_contig_clear_max_seg_size() to kfree memory that was not allocated by vb2_dma_contig_set_max_seg_size(). The assumption in vb2_dma_contig_set_max_seg_size() seems to be that dev->dma_parms is always NULL when the driver is probed, and the case where dev->dma_parms has bee initialized by someone else than the driver (by calling vb2_dma_contig_set_max_seg_size) will cause a failure. All the current users of these functions are platform devices, which now always have dma_parms set by the driver core. To fix the issue for v5.7, make vb2_dma_contig_set_max_seg_size() return an error if dma_parms is NULL to be on the safe side, and remove the kfree code from vb2_dma_contig_clear_max_seg_size(). For v5.8 we should remove the two functions and move the dma_set_max_seg_size() calls into the drivers. Signed-off-by: Tomi Valkeinen <[email protected]> Fixes: 9495b7e ("driver core: platform: Initialize dma_parms for platform devices") Cc: [email protected] Acked-by: Marek Szyprowski <[email protected]> Reviewed-by: Ulf Hansson <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 5be5f41 commit 0d96687

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

drivers/media/common/videobuf2/videobuf2-dma-contig.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,8 @@ EXPORT_SYMBOL_GPL(vb2_dma_contig_memops);
726726
int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size)
727727
{
728728
if (!dev->dma_parms) {
729-
dev->dma_parms = kzalloc(sizeof(*dev->dma_parms), GFP_KERNEL);
730-
if (!dev->dma_parms)
731-
return -ENOMEM;
729+
dev_err(dev, "Failed to set max_seg_size: dma_parms is NULL\n");
730+
return -ENODEV;
732731
}
733732
if (dma_get_max_seg_size(dev) < size)
734733
return dma_set_max_seg_size(dev, size);
@@ -737,21 +736,6 @@ int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size)
737736
}
738737
EXPORT_SYMBOL_GPL(vb2_dma_contig_set_max_seg_size);
739738

740-
/*
741-
* vb2_dma_contig_clear_max_seg_size() - release resources for DMA parameters
742-
* @dev: device for configuring DMA parameters
743-
*
744-
* This function releases resources allocated to configure DMA parameters
745-
* (see vb2_dma_contig_set_max_seg_size() function). It should be called from
746-
* device drivers on driver remove.
747-
*/
748-
void vb2_dma_contig_clear_max_seg_size(struct device *dev)
749-
{
750-
kfree(dev->dma_parms);
751-
dev->dma_parms = NULL;
752-
}
753-
EXPORT_SYMBOL_GPL(vb2_dma_contig_clear_max_seg_size);
754-
755739
MODULE_DESCRIPTION("DMA-contig memory handling routines for videobuf2");
756740
MODULE_AUTHOR("Pawel Osciak <[email protected]>");
757741
MODULE_LICENSE("GPL");

include/media/videobuf2-dma-contig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no)
2525
}
2626

2727
int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size);
28-
void vb2_dma_contig_clear_max_seg_size(struct device *dev);
28+
static inline void vb2_dma_contig_clear_max_seg_size(struct device *dev) { }
2929

3030
extern const struct vb2_mem_ops vb2_dma_contig_memops;
3131

0 commit comments

Comments
 (0)