From: Andreas Bombe Date: Sun, 21 Mar 2010 19:02:45 +0000 (-0300) Subject: V4L/DVB: V4L2: Replace loops for finding max buffers in VIDIOC_REQBUFS callbacks X-Git-Tag: firefly_0821_release~9833^2~2094^2~205 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=dab7e3106ddd6cbc3b55301228407b9d17ce7773;p=firefly-linux-kernel-4.4.55.git 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: Andreas Bombe Signed-off-by: Mauro Carvalho Chehab --- diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c index f4860f03dfc3..350e7af75884 100644 --- a/drivers/media/video/bt8xx/bttv-driver.c +++ b/drivers/media/video/bt8xx/bttv-driver.c @@ -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; if (0 == *count) *count = gbuffers; - while (*size * *count > gbuffers * gbufsize) - (*count)--; + if (*size * *count > gbuffers * gbufsize) + *count = (gbuffers * gbufsize) / *size; return 0; } diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c index 2d3ac8b83dc3..543b854f6a62 100644 --- a/drivers/media/video/cx23885/cx23885-video.c +++ b/drivers/media/video/cx23885/cx23885-video.c @@ -514,8 +514,8 @@ static int buffer_setup(struct videobuf_queue *q, unsigned int *count, *size = fh->fmt->depth*fh->width*fh->height >> 3; if (0 == *count) *count = 32; - while (*size * *count > vid_limit * 1024 * 1024) - (*count)--; + if (*size * *count > vid_limit * 1024 * 1024) + *count = (vid_limit * 1024 * 1024) / *size; return 0; } diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c index 8e414f7aa76e..0a3849c710f8 100644 --- a/drivers/media/video/cx88/cx88-video.c +++ b/drivers/media/video/cx88/cx88-video.c @@ -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; if (0 == *count) *count = 32; - while (*size * *count > vid_limit * 1024 * 1024) - (*count)--; + if (*size * *count > vid_limit * 1024 * 1024) + *count = (vid_limit * 1024 * 1024) / *size; return 0; } diff --git a/drivers/media/video/mx1_camera.c b/drivers/media/video/mx1_camera.c index 34a66019190e..5c17f9ec3d7c 100644 --- a/drivers/media/video/mx1_camera.c +++ b/drivers/media/video/mx1_camera.c @@ -139,8 +139,8 @@ static int mx1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, if (!*count) *count = 32; - while (*size * *count > MAX_VIDEO_MEM * 1024 * 1024) - (*count)--; + if (*size * *count > MAX_VIDEO_MEM * 1024 * 1024) + *count = (MAX_VIDEO_MEM * 1024 * 1024) / *size; dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size); diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c index ce76d952e161..f85b2ed8a2d8 100644 --- a/drivers/media/video/omap24xxcam.c +++ b/drivers/media/video/omap24xxcam.c @@ -452,8 +452,8 @@ static int omap24xxcam_vbq_setup(struct videobuf_queue *vbq, unsigned int *cnt, *size = fh->pix.sizeimage; /* accessing fh->cam->capture_mem is ok, it's constant */ - while (*size * *cnt > fh->cam->capture_mem) - (*cnt)--; + if (*size * *cnt > fh->cam->capture_mem) + *cnt = fh->cam->capture_mem / *size; return 0; } diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c index 04bf5c11308d..7fe70e718656 100644 --- a/drivers/media/video/pxa_camera.c +++ b/drivers/media/video/pxa_camera.c @@ -253,8 +253,8 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count, if (0 == *count) *count = 32; - while (*size * *count > vid_limit * 1024 * 1024) - (*count)--; + if (*size * *count > vid_limit * 1024 * 1024) + *count = (vid_limit * 1024 * 1024) / *size; return 0; } diff --git a/drivers/media/video/s2255drv.c b/drivers/media/video/s2255drv.c index 0092ff52bb27..5ecd41b3bf3e 100644 --- a/drivers/media/video/s2255drv.c +++ b/drivers/media/video/s2255drv.c @@ -702,8 +702,8 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count, if (0 == *count) *count = S2255_DEF_BUFS; - while (*size * (*count) > vid_limit * 1024 * 1024) - (*count)--; + if (*size * *count > vid_limit * 1024 * 1024) + *count = (vid_limit * 1024 * 1024) / *size; return 0; } diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c index 7a229ebe6923..9a46f0a0c1bb 100644 --- a/drivers/media/video/sh_mobile_ceu_camera.c +++ b/drivers/media/video/sh_mobile_ceu_camera.c @@ -213,8 +213,8 @@ static int sh_mobile_ceu_videobuf_setup(struct videobuf_queue *vq, *count = 2; if (pcdev->video_limit) { - while (PAGE_ALIGN(*size) * *count > pcdev->video_limit) - (*count)--; + if (PAGE_ALIGN(*size) * *count > pcdev->video_limit) + *count = pcdev->video_limit / PAGE_ALIGN(*size); } dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size); diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c index cdbe70385c12..5a736b8a5a33 100644 --- a/drivers/media/video/vivi.c +++ b/drivers/media/video/vivi.c @@ -749,8 +749,8 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) if (0 == *count) *count = 32; - while (*size * *count > vid_limit * 1024 * 1024) - (*count)--; + if (*size * *count > vid_limit * 1024 * 1024) + *count = (vid_limit * 1024 * 1024) / *size; dprintk(dev, 1, "%s, count=%d, size=%d\n", __func__, *count, *size); diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c index 3d4bac252902..a82b5bd18d26 100644 --- a/drivers/media/video/zr364xx.c +++ b/drivers/media/video/zr364xx.c @@ -376,8 +376,8 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count, if (*count == 0) *count = ZR364XX_DEF_BUFS; - while (*size * (*count) > ZR364XX_DEF_BUFS * 1024 * 1024) - (*count)--; + if (*size * *count > ZR364XX_DEF_BUFS * 1024 * 1024) + *count = (ZR364XX_DEF_BUFS * 1024 * 1024) / *size; return 0; } diff --git a/drivers/staging/cx25821/cx25821-video.c b/drivers/staging/cx25821/cx25821-video.c index 91e0db2e37f9..a3bea2739cef 100644 --- a/drivers/staging/cx25821/cx25821-video.c +++ b/drivers/staging/cx25821/cx25821-video.c @@ -516,8 +516,8 @@ int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count, if (0 == *count) *count = 32; - while (*size * *count > vid_limit * 1024 * 1024) - (*count)--; + if (*size * *count > vid_limit * 1024 * 1024) + *count = (vid_limit * 1024 * 1024) / *size; return 0; }