Skip to contentSkip to conversation

media: vivid: sizeimage/CREATE_BUFS fixes

PATCH New Hans Verkuil 1 participant 3 messages Jun 26, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover media: vivid: sizeimage/CREATE_BUFS fixes

After improving the CREATE_BUFS tests in v4l2-compliance I discovered several bugs in the vivid driver, primarily related to the multiplanar formats and the queue_setup callback.

This series fixes those bugs in order to make the regression tests pass once the v4l2-compliance fixes are committed.

Regards,

Hans

Hans Verkuil (2):
media: vivid: fix wrong sizeimage value for mplane
media: vivid: fix CREATE_BUFS support in queue_setup()

 drivers/media/test-drivers/vivid/vivid-sdr-cap.c |  7 ++++++-
 .../media/test-drivers/vivid/vivid-touch-cap.c   |  6 +++---
 drivers/media/test-drivers/vivid/vivid-vbi-cap.c |  2 ++
 drivers/media/test-drivers/vivid/vivid-vbi-out.c |  2 ++
 drivers/media/test-drivers/vivid/vivid-vid-cap.c |  5 +++--
 drivers/media/test-drivers/vivid/vivid-vid-out.c | 16 +++++++++-------
 6 files changed, 25 insertions(+), 13 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 media: vivid: fix wrong sizeimage value for mplane

In several places a division by fmt->vdownsampling[p] was missing in the sizeimage[p] calculation, causing incorrect behavior for multiplanar formats were some planes are smaller than the first plane.

Found by new v4l2-compliance tests.

---
 drivers/media/test-drivers/vivid/vivid-vid-cap.c |  5 +++--
 drivers/media/test-drivers/vivid/vivid-vid-out.c | 16 +++++++++-------
 2 files changed, 12 insertions(+), 9 deletions(-)
drivers/media/test-drivers/vivid/vivid-vid-cap.c +3 -2
index 2804975fe278..3a3041a0378f 100644
@@ -106,8 +106,9 @@ static int vid_cap_queue_setup(struct vb2_queue *vq,
 		if (*nplanes != buffers)
 			return -EINVAL;
 		for (p = 0; p < buffers; p++) {
-			if (sizes[p] < tpg_g_line_width(&dev->tpg, p) * h +
-						dev->fmt_cap->data_offset[p])
+			if (sizes[p] < tpg_g_line_width(&dev->tpg, p) * h /
+					dev->fmt_cap->vdownsampling[p] +
+					dev->fmt_cap->data_offset[p])
 				return -EINVAL;
 		}
 	} else {
drivers/media/test-drivers/vivid/vivid-vid-out.c +9 -7
index 1653b2988f7e..7a0f4c61ac80 100644
@@ -63,14 +63,16 @@ static int vid_out_queue_setup(struct vb2_queue *vq,
 		if (sizes[0] < size)
 			return -EINVAL;
 		for (p = 1; p < planes; p++) {
-			if (sizes[p] < dev->bytesperline_out[p] * h +
-				       vfmt->data_offset[p])
+			if (sizes[p] < dev->bytesperline_out[p] * h /
+					vfmt->vdownsampling[p] +
+					vfmt->data_offset[p])
 				return -EINVAL;
 		}
 	} else {
 		for (p = 0; p < planes; p++)
-			sizes[p] = p ? dev->bytesperline_out[p] * h +
-				       vfmt->data_offset[p] : size;
+			sizes[p] = p ? dev->bytesperline_out[p] * h /
+					vfmt->vdownsampling[p] +
+					vfmt->data_offset[p] : size;
 	}
 
 	*nplanes = planes;
@@ -124,7 +126,7 @@ static int vid_out_buf_prepare(struct vb2_buffer *vb)
 
 	for (p = 0; p < planes; p++) {
 		if (p)
-			size = dev->bytesperline_out[p] * h;
+			size = dev->bytesperline_out[p] * h / vfmt->vdownsampling[p];
 		size += vb->planes[p].data_offset;
 
 		if (vb2_get_plane_payload(vb, p) < size) {
@@ -331,8 +333,8 @@ int vivid_g_fmt_vid_out(struct file *file, void *priv,
 	for (p = 0; p < mp->num_planes; p++) {
 		mp->plane_fmt[p].bytesperline = dev->bytesperline_out[p];
 		mp->plane_fmt[p].sizeimage =
-			mp->plane_fmt[p].bytesperline * mp->height +
-			fmt->data_offset[p];
+			mp->plane_fmt[p].bytesperline * mp->height /
+			fmt->vdownsampling[p] + fmt->data_offset[p];
 	}
 	for (p = fmt->buffers; p < fmt->planes; p++) {
 		unsigned stride = dev->bytesperline_out[p];
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 media: vivid: fix CREATE_BUFS support in queue_setup()

In reply to Hans Verkuil

While queue_setup was correct for CREATE_BUFS support for video devices, for VBI, SDR and touch devices it was wrong.

This was found after adding new v4l2-compliance tests.

---
 drivers/media/test-drivers/vivid/vivid-sdr-cap.c   | 7 ++++++-
 drivers/media/test-drivers/vivid/vivid-touch-cap.c | 6 +++---
 drivers/media/test-drivers/vivid/vivid-vbi-cap.c   | 2 ++
 drivers/media/test-drivers/vivid/vivid-vbi-out.c   | 2 ++
 4 files changed, 13 insertions(+), 4 deletions(-)
drivers/media/test-drivers/vivid/vivid-sdr-cap.c +6 -1
index a81f26b76988..38cda33dffb2 100644
@@ -219,8 +219,13 @@ static int sdr_cap_queue_setup(struct vb2_queue *vq,
 		       unsigned sizes[], struct device *alloc_devs[])
 {
 	/* 2 = max 16-bit sample returned */
-	sizes[0] = SDR_CAP_SAMPLES_PER_BUF * 2;
+	u32 size = SDR_CAP_SAMPLES_PER_BUF * 2;
+
+	if (*nplanes)
+		return sizes[0] < size ? -EINVAL : 0;
+
 	*nplanes = 1;
+	sizes[0] = size;
 	return 0;
 }
 
drivers/media/test-drivers/vivid/vivid-touch-cap.c +3 -3
index 3888c21b4d0c..3600b084bca5 100644
@@ -17,13 +17,13 @@ static int touch_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers,
 	unsigned int size = f->sizeimage;
 
 	if (*nplanes) {
-		if (sizes[0] < size)
+		if (*nplanes != 1)
 			return -EINVAL;
-	} else {
-		sizes[0] = size;
+		return sizes[0] < size ? -EINVAL : 0;
 	}
 
 	*nplanes = 1;
+	sizes[0] = size;
 	return 0;
 }
 
drivers/media/test-drivers/vivid/vivid-vbi-cap.c +2 -0
index 3840b3a664ac..95387d57eb93 100644
@@ -132,6 +132,8 @@ static int vbi_cap_queue_setup(struct vb2_queue *vq,
 	if (!vivid_is_sdtv_cap(dev))
 		return -EINVAL;
 
+	if (*nplanes)
+		return sizes[0] < size ? -EINVAL : 0;
 	sizes[0] = size;
 
 	*nplanes = 1;
drivers/media/test-drivers/vivid/vivid-vbi-out.c +2 -0
index 434a10676417..871a56d93425 100644
@@ -28,6 +28,8 @@ static int vbi_out_queue_setup(struct vb2_queue *vq,
 	if (!vivid_is_svid_out(dev))
 		return -EINVAL;
 
+	if (*nplanes)
+		return sizes[0] < size ? -EINVAL : 0;
 	sizes[0] = size;
 
 	*nplanes = 1;
Signature · 1 line
2.43.0