From f6f611618cd6c533feff0c5004d1f4f3af0af2d2 Mon Sep 17 00:00:00 2001
From: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Date: Tue, 9 Jun 2009 11:19:07 +0200
Subject: [PATCH 25/38] soc-camera: prohibit geometry change with initialised buffers

Prohibit S_FMT and S_CROP with a different window width or height after video
buffer initialisation. This simplifies the work to be done in specific host and
client drivers, and it doesn't seem to make much sense to allow these changes.
We do however allow S_CROP with equal width and height to just move the window,
this doesn't affect video buffer management and is usually easy enough to
implement.

Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
---
 drivers/media/video/soc_camera.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index a22fcd0..21a8aa5 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -517,8 +517,8 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv,
 
 	mutex_lock(&icf->vb_vidq.vb_lock);
 
-	if (videobuf_queue_is_busy(&icf->vb_vidq)) {
-		dev_err(&icd->dev, "S_FMT denied: queue busy\n");
+	if (icf->vb_vidq.bufs[0]) {
+		dev_err(&icd->dev, "S_FMT denied: queue initialised\n");
 		ret = -EBUSY;
 		goto unlock;
 	}
@@ -768,6 +768,15 @@ static int soc_camera_s_crop(struct file *file, void *fh,
 	/* Cropping is allowed during a running capture, guard consistency */
 	mutex_lock(&icf->vb_vidq.vb_lock);
 
+	/* Prohibit window size change with initialised buffers */
+	if (icf->vb_vidq.bufs[0] && (rect.width != icd->rect_current.width ||
+				     rect.height != icd->rect_current.height)) {
+		dev_err(&icd->dev,
+			"S_CROP denied: queue initialised and sizes differ\n");
+		ret = -EBUSY;
+		goto unlock;
+	}
+
 	if (rect.width > icd->rect_max.width)
 		rect.width = icd->rect_max.width;
 
@@ -792,6 +801,7 @@ static int soc_camera_s_crop(struct file *file, void *fh,
 	if (!ret)
 		icd->rect_current = rect;
 
+unlock:
 	mutex_unlock(&icf->vb_vidq.vb_lock);
 
 	return ret;
-- 
1.6.2.4

