[PATCH RFT/RFC v2 43/47] staging: media: zoran: fix use of buffer_size and sizeimage

From: Corentin Labbe
Date: Fri Sep 25 2020 - 14:35:35 EST


buffer_size was not set when it should be.
Furthermore, use it instead of recalculate it.

Signed-off-by: Corentin Labbe <clabbe@xxxxxxxxxxxx>
---
drivers/staging/media/zoran/zoran_card.c | 2 ++
drivers/staging/media/zoran/zoran_driver.c | 9 ++++++---
2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/media/zoran/zoran_card.c b/drivers/staging/media/zoran/zoran_card.c
index 89fbc114c368..d7b3efa9e39f 100644
--- a/drivers/staging/media/zoran/zoran_card.c
+++ b/drivers/staging/media/zoran/zoran_card.c
@@ -857,6 +857,8 @@ void zoran_open_init_params(struct zoran *zr)
if (i)
pci_err(zr->pci_dev, "%s internal error\n", __func__);

+ zr->buffer_size = zr->v4l_settings.bytesperline * zr->v4l_settings.height;
+
clear_interrupt_counters(zr);
}

diff --git a/drivers/staging/media/zoran/zoran_driver.c b/drivers/staging/media/zoran/zoran_driver.c
index 5dacbeac790b..021073ba08e6 100644
--- a/drivers/staging/media/zoran/zoran_driver.c
+++ b/drivers/staging/media/zoran/zoran_driver.c
@@ -407,6 +407,8 @@ static int zoran_v4l_set_format(struct zoran *zr, int width, int height,

bpp = (format->depth + 7) / 8;

+ zr->buffer_size = height * width * bpp;
+
/* Check against available buffer size */
if (height * width * bpp > zr->buffer_size) {
pci_err(zr->pci_dev, "%s - video buffer size (%d kB) is too small\n",
@@ -1100,7 +1102,7 @@ static int zoran_g_fmt_vid_out(struct file *file, void *__fh,
fmt->fmt.pix.width = zr->jpg_settings.img_width / zr->jpg_settings.HorDcm;
fmt->fmt.pix.height = zr->jpg_settings.img_height * 2 /
(zr->jpg_settings.VerDcm * zr->jpg_settings.TmpDcm);
- fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(&zr->jpg_settings);
+ fmt->fmt.pix.sizeimage = zr->buffer_size;
fmt->fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
if (zr->jpg_settings.TmpDcm == 1)
fmt->fmt.pix.field = (zr->jpg_settings.odd_even ?
@@ -1125,7 +1127,7 @@ static int zoran_g_fmt_vid_cap(struct file *file, void *__fh,

fmt->fmt.pix.width = zr->v4l_settings.width;
fmt->fmt.pix.height = zr->v4l_settings.height;
- fmt->fmt.pix.sizeimage = zr->v4l_settings.bytesperline * zr->v4l_settings.height;
+ fmt->fmt.pix.sizeimage = zr->buffer_size;
fmt->fmt.pix.pixelformat = zr->v4l_settings.format->fourcc;
fmt->fmt.pix.colorspace = zr->v4l_settings.format->colorspace;
fmt->fmt.pix.bytesperline = zr->v4l_settings.bytesperline;
@@ -1194,6 +1196,7 @@ static int zoran_try_fmt_vid_out(struct file *file, void *__fh,
V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM);

fmt->fmt.pix.sizeimage = zoran_v4l2_calc_bufsize(&settings);
+ zr->buffer_size = fmt->fmt.pix.sizeimage;
fmt->fmt.pix.bytesperline = 0;
fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
return res;
@@ -1352,7 +1355,7 @@ static int zoran_s_fmt_vid_cap(struct file *file, void *__fh,

/* tell the user the results/missing stuff */
fmt->fmt.pix.bytesperline = zr->v4l_settings.bytesperline;
- fmt->fmt.pix.sizeimage = zr->v4l_settings.height * zr->v4l_settings.bytesperline;
+ fmt->fmt.pix.sizeimage = zr->buffer_size;
fmt->fmt.pix.colorspace = zr->v4l_settings.format->colorspace;
if (BUZ_MAX_HEIGHT < (zr->v4l_settings.height * 2))
fmt->fmt.pix.field = V4L2_FIELD_INTERLACED;
--
2.26.2