Commit dab7e310 authored by Andreas Bombe's avatar Andreas Bombe Committed by Mauro Carvalho Chehab

V4L/DVB: V4L2: Replace loops for finding max buffers in VIDIOC_REQBUFS callbacks

Due to obvious copy and paste coding a number of video capture drivers
which implement a limit on the buffer memory decremented the user
supplied buffer count in a while loop until it reaches an acceptable
value.

This is a silly thing to do when the maximum value can be directly
computed.
Signed-off-by: default avatarAndreas Bombe <aeb@debian.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 0a062033
...@@ -1806,8 +1806,8 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) ...@@ -1806,8 +1806,8 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
*size = fh->fmt->depth*fh->width*fh->height >> 3; *size = fh->fmt->depth*fh->width*fh->height >> 3;
if (0 == *count) if (0 == *count)
*count = gbuffers; *count = gbuffers;
while (*size * *count > gbuffers * gbufsize) if (*size * *count > gbuffers * gbufsize)
(*count)--; *count = (gbuffers * gbufsize) / *size;
return 0; return 0;
} }
......
...@@ -514,8 +514,8 @@ static int buffer_setup(struct videobuf_queue *q, unsigned int *count, ...@@ -514,8 +514,8 @@ static int buffer_setup(struct videobuf_queue *q, unsigned int *count,
*size = fh->fmt->depth*fh->width*fh->height >> 3; *size = fh->fmt->depth*fh->width*fh->height >> 3;
if (0 == *count) if (0 == *count)
*count = 32; *count = 32;
while (*size * *count > vid_limit * 1024 * 1024) if (*size * *count > vid_limit * 1024 * 1024)
(*count)--; *count = (vid_limit * 1024 * 1024) / *size;
return 0; return 0;
} }
......
...@@ -561,8 +561,8 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size) ...@@ -561,8 +561,8 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
*size = fh->fmt->depth*fh->width*fh->height >> 3; *size = fh->fmt->depth*fh->width*fh->height >> 3;
if (0 == *count) if (0 == *count)
*count = 32; *count = 32;
while (*size * *count > vid_limit * 1024 * 1024) if (*size * *count > vid_limit * 1024 * 1024)
(*count)--; *count = (vid_limit * 1024 * 1024) / *size;
return 0; return 0;
} }
......
...@@ -139,8 +139,8 @@ static int mx1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, ...@@ -139,8 +139,8 @@ static int mx1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
if (!*count) if (!*count)
*count = 32; *count = 32;
while (*size * *count > MAX_VIDEO_MEM * 1024 * 1024) if (*size * *count > MAX_VIDEO_MEM * 1024 * 1024)
(*count)--; *count = (MAX_VIDEO_MEM * 1024 * 1024) / *size;
dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size); dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size);
......
...@@ -452,8 +452,8 @@ static int omap24xxcam_vbq_setup(struct videobuf_queue *vbq, unsigned int *cnt, ...@@ -452,8 +452,8 @@ static int omap24xxcam_vbq_setup(struct videobuf_queue *vbq, unsigned int *cnt,
*size = fh->pix.sizeimage; *size = fh->pix.sizeimage;
/* accessing fh->cam->capture_mem is ok, it's constant */ /* accessing fh->cam->capture_mem is ok, it's constant */
while (*size * *cnt > fh->cam->capture_mem) if (*size * *cnt > fh->cam->capture_mem)
(*cnt)--; *cnt = fh->cam->capture_mem / *size;
return 0; return 0;
} }
......
...@@ -253,8 +253,8 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, ...@@ -253,8 +253,8 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
if (0 == *count) if (0 == *count)
*count = 32; *count = 32;
while (*size * *count > vid_limit * 1024 * 1024) if (*size * *count > vid_limit * 1024 * 1024)
(*count)--; *count = (vid_limit * 1024 * 1024) / *size;
return 0; return 0;
} }
......
...@@ -702,8 +702,8 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count, ...@@ -702,8 +702,8 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count,
if (0 == *count) if (0 == *count)
*count = S2255_DEF_BUFS; *count = S2255_DEF_BUFS;
while (*size * (*count) > vid_limit * 1024 * 1024) if (*size * *count > vid_limit * 1024 * 1024)
(*count)--; *count = (vid_limit * 1024 * 1024) / *size;
return 0; return 0;
} }
......
...@@ -213,8 +213,8 @@ static int sh_mobile_ceu_videobuf_setup(struct videobuf_queue *vq, ...@@ -213,8 +213,8 @@ static int sh_mobile_ceu_videobuf_setup(struct videobuf_queue *vq,
*count = 2; *count = 2;
if (pcdev->video_limit) { if (pcdev->video_limit) {
while (PAGE_ALIGN(*size) * *count > pcdev->video_limit) if (PAGE_ALIGN(*size) * *count > pcdev->video_limit)
(*count)--; *count = pcdev->video_limit / PAGE_ALIGN(*size);
} }
dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size); dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size);
......
...@@ -749,8 +749,8 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) ...@@ -749,8 +749,8 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
if (0 == *count) if (0 == *count)
*count = 32; *count = 32;
while (*size * *count > vid_limit * 1024 * 1024) if (*size * *count > vid_limit * 1024 * 1024)
(*count)--; *count = (vid_limit * 1024 * 1024) / *size;
dprintk(dev, 1, "%s, count=%d, size=%d\n", __func__, dprintk(dev, 1, "%s, count=%d, size=%d\n", __func__,
*count, *size); *count, *size);
......
...@@ -376,8 +376,8 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count, ...@@ -376,8 +376,8 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count,
if (*count == 0) if (*count == 0)
*count = ZR364XX_DEF_BUFS; *count = ZR364XX_DEF_BUFS;
while (*size * (*count) > ZR364XX_DEF_BUFS * 1024 * 1024) if (*size * *count > ZR364XX_DEF_BUFS * 1024 * 1024)
(*count)--; *count = (ZR364XX_DEF_BUFS * 1024 * 1024) / *size;
return 0; return 0;
} }
......
...@@ -516,8 +516,8 @@ int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count, ...@@ -516,8 +516,8 @@ int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count,
if (0 == *count) if (0 == *count)
*count = 32; *count = 32;
while (*size * *count > vid_limit * 1024 * 1024) if (*size * *count > vid_limit * 1024 * 1024)
(*count)--; *count = (vid_limit * 1024 * 1024) / *size;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment