V4L/DVB (10933): zoran: Pass zoran_fh pointers instead of file pointers

Many functions had a struct file pointer argument, but all they wants is
the struct zoran_fh pointer from the file's private data.  Since every
caller of those functions already has the zoran_fh, just pass the that
instead.  This saves a dereference in each function change.

While I'm at it, change the code formatting of affected functions to be
kernel standard style.

Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
diff --git a/drivers/media/video/zoran/zoran_device.c b/drivers/media/video/zoran/zoran_device.c
index 4dc9513..f8bcd1a 100644
--- a/drivers/media/video/zoran/zoran_device.c
+++ b/drivers/media/video/zoran/zoran_device.c
@@ -535,12 +535,8 @@
  *  and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
  */
 
-void
-write_overlay_mask (struct file       *file,
-		    struct v4l2_clip *vp,
-		    int                count)
+void write_overlay_mask(struct zoran_fh *fh, struct v4l2_clip *vp, int count)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
 	u32 *mask;
diff --git a/drivers/media/video/zoran/zoran_device.h b/drivers/media/video/zoran/zoran_device.h
index 3520bd5..85414e1 100644
--- a/drivers/media/video/zoran/zoran_device.h
+++ b/drivers/media/video/zoran/zoran_device.h
@@ -54,7 +54,7 @@
 /* zr360x7 access to raw capture */
 extern void zr36057_overlay(struct zoran *zr,
 			    int on);
-extern void write_overlay_mask(struct file *file,
+extern void write_overlay_mask(struct zoran_fh *fh,
 			       struct v4l2_clip *vp,
 			       int count);
 extern void zr36057_set_memgrab(struct zoran *zr,
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c
index e22378a..5343a8a 100644
--- a/drivers/media/video/zoran/zoran_driver.c
+++ b/drivers/media/video/zoran/zoran_driver.c
@@ -186,8 +186,8 @@
 }
 
 /* forward references */
-static void v4l_fbuffer_free(struct file *file);
-static void jpg_fbuffer_free(struct file *file);
+static void v4l_fbuffer_free(struct zoran_fh *fh);
+static void jpg_fbuffer_free(struct zoran_fh *fh);
 
 /* Set mapping mode */
 static void map_mode_raw(struct zoran_fh *fh)
@@ -213,10 +213,8 @@
  *   These have to be pysically contiguous.
  */
 
-static int
-v4l_fbuffer_alloc (struct file *file)
+static int v4l_fbuffer_alloc(struct zoran_fh *fh)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	int i, off;
 	unsigned char *mem;
@@ -236,7 +234,7 @@
 				KERN_ERR
 				"%s: v4l_fbuffer_alloc() - kmalloc for V4L buf %d failed\n",
 				ZR_DEVNAME(zr), i);
-			v4l_fbuffer_free(file);
+			v4l_fbuffer_free(fh);
 			return -ENOBUFS;
 		}
 		fh->buffers.buffer[i].v4l.fbuffer = mem;
@@ -258,10 +256,8 @@
 }
 
 /* free the V4L grab buffers */
-static void
-v4l_fbuffer_free (struct file *file)
+static void v4l_fbuffer_free(struct zoran_fh *fh)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	int i, off;
 	unsigned char *mem;
@@ -311,10 +307,8 @@
  *       and fragment buffers are not little-endian.
  */
 
-static int
-jpg_fbuffer_alloc (struct file *file)
+static int jpg_fbuffer_alloc(struct zoran_fh *fh)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	int i, j, off;
 	u8 *mem;
@@ -334,7 +328,7 @@
 				KERN_ERR
 				"%s: jpg_fbuffer_alloc() - get_zeroed_page (frag_tab) failed for buffer %d\n",
 				ZR_DEVNAME(zr), i);
-			jpg_fbuffer_free(file);
+			jpg_fbuffer_free(fh);
 			return -ENOBUFS;
 		}
 		fh->buffers.buffer[i].jpg.frag_tab = (__le32 *)mem;
@@ -347,7 +341,7 @@
 					KERN_ERR
 					"%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n",
 					ZR_DEVNAME(zr), i);
-				jpg_fbuffer_free(file);
+				jpg_fbuffer_free(fh);
 				return -ENOBUFS;
 			}
 			fh->buffers.buffer[i].jpg.frag_tab[0] =
@@ -365,7 +359,7 @@
 						KERN_ERR
 						"%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n",
 						ZR_DEVNAME(zr), i);
-					jpg_fbuffer_free(file);
+					jpg_fbuffer_free(fh);
 					return -ENOBUFS;
 				}
 
@@ -391,10 +385,8 @@
 }
 
 /* free the MJPEG grab buffers */
-static void
-jpg_fbuffer_free (struct file *file)
+static void jpg_fbuffer_free(struct zoran_fh *fh)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	int i, j, off;
 	unsigned char *mem;
@@ -492,11 +484,8 @@
 	return 0;
 }
 
-static int
-zoran_v4l_queue_frame (struct file *file,
-		       int          num)
+static int zoran_v4l_queue_frame(struct zoran_fh *fh, int num)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	unsigned long flags;
 	int res = 0;
@@ -574,11 +563,8 @@
  * Sync on a V4L buffer
  */
 
-static int
-v4l_sync (struct file *file,
-	  int          frame)
+static int v4l_sync(struct zoran_fh *fh, int frame)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	unsigned long flags;
 
@@ -643,12 +629,9 @@
  *   Queue a MJPEG buffer for capture/playback
  */
 
-static int
-zoran_jpg_queue_frame (struct file          *file,
-		       int                   num,
-		       enum zoran_codec_mode mode)
+static int zoran_jpg_queue_frame(struct zoran_fh *fh, int num,
+				 enum zoran_codec_mode mode)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	unsigned long flags;
 	int res = 0;
@@ -738,12 +721,8 @@
 	return res;
 }
 
-static int
-jpg_qbuf (struct file          *file,
-	  int                   frame,
-	  enum zoran_codec_mode mode)
+static int jpg_qbuf(struct zoran_fh *fh, int frame, enum zoran_codec_mode mode)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	int res = 0;
 
@@ -770,7 +749,7 @@
 		}
 	}
 
-	if ((res = zoran_jpg_queue_frame(file, frame, mode)))
+	if ((res = zoran_jpg_queue_frame(fh, frame, mode)))
 		return res;
 
 	/* Start the jpeg codec when the first frame is queued  */
@@ -784,11 +763,8 @@
  *   Sync on a MJPEG buffer
  */
 
-static int
-jpg_sync (struct file       *file,
-	  struct zoran_sync *bs)
+static int jpg_sync(struct zoran_fh *fh, struct zoran_sync *bs)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	unsigned long flags;
 	int frame;
@@ -852,11 +828,9 @@
 	return 0;
 }
 
-static void
-zoran_open_init_session (struct file *file)
+static void zoran_open_init_session(struct zoran_fh *fh)
 {
 	int i;
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 
 	/* Per default, map the V4L Buffers */
@@ -883,10 +857,8 @@
 	fh->buffers.active = ZORAN_FREE;
 }
 
-static void
-zoran_close_end_session (struct file *file)
+static void zoran_close_end_session(struct zoran_fh *fh)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 
 	/* overlay */
@@ -912,7 +884,7 @@
 
 		/* v4l buffers */
 		if (fh->buffers.allocated)
-			v4l_fbuffer_free(file);
+			v4l_fbuffer_free(fh);
 	} else {
 		/* jpg capture */
 		if (fh->buffers.active != ZORAN_FREE) {
@@ -923,7 +895,7 @@
 
 		/* jpg buffers */
 		if (fh->buffers.allocated)
-			jpg_fbuffer_free(file);
+			jpg_fbuffer_free(fh);
 	}
 }
 
@@ -989,7 +961,7 @@
 	/* set file_ops stuff */
 	file->private_data = fh;
 	fh->zr = zr;
-	zoran_open_init_session(file);
+	zoran_open_init_session(fh);
 	unlock_kernel();
 
 	return 0;
@@ -1018,7 +990,7 @@
 	 * (prevents deadlocks) */
 	/*mutex_lock(&zr->resource_lock);*/
 
-	zoran_close_end_session(file);
+	zoran_close_end_session(fh);
 
 	if (zr->user-- == 1) {	/* Last process */
 		/* Clean up JPEG process */
@@ -1085,15 +1057,13 @@
 	return -EINVAL;
 }
 
-static int
-setup_fbuffer (struct file               *file,
+static int setup_fbuffer(struct zoran_fh *fh,
 	       void                      *base,
 	       const struct zoran_format *fmt,
 	       int                        width,
 	       int                        height,
 	       int                        bytesperline)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 
 	/* (Ronald) v4l/v4l2 guidelines */
@@ -1163,17 +1133,9 @@
 }
 
 
-static int
-setup_window (struct file       *file,
-	      int                x,
-	      int                y,
-	      int                width,
-	      int                height,
-	      struct v4l2_clip __user *clips,
-	      int                clipcount,
-	      void              __user *bitmap)
+static int setup_window(struct zoran_fh *fh, int x, int y, int width, int height,
+	struct v4l2_clip __user *clips, int clipcount, void __user *bitmap)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 	struct v4l2_clip *vcp = NULL;
 	int on, end;
@@ -1273,7 +1235,7 @@
 			vfree(vcp);
 			return -EFAULT;
 		}
-		write_overlay_mask(file, vcp, clipcount);
+		write_overlay_mask(fh, vcp, clipcount);
 		vfree(vcp);
 	}
 
@@ -1289,11 +1251,8 @@
 	return wait_grab_pending(zr);
 }
 
-static int
-setup_overlay (struct file *file,
-	       int          on)
+static int setup_overlay(struct zoran_fh *fh, int on)
 {
-	struct zoran_fh *fh = file->private_data;
 	struct zoran *zr = fh->zr;
 
 	/* If there is nothing to do, return immediatly */
@@ -1356,11 +1315,9 @@
 	return wait_grab_pending(zr);
 }
 
-	/* get the status of a buffer in the clients buffer queue */
-static int
-zoran_v4l2_buffer_status (struct zoran_fh    *fh,
-			  struct v4l2_buffer *buf,
-			  int                 num)
+/* get the status of a buffer in the clients buffer queue */
+static int zoran_v4l2_buffer_status(struct zoran_fh *fh,
+				    struct v4l2_buffer *buf, int num)
 {
 	struct zoran *zr = fh->zr;
 	unsigned long flags;
@@ -1727,7 +1684,7 @@
 		fh->buffers.num_buffers = breq->count;
 		fh->buffers.buffer_size = breq->size;
 
-		if (jpg_fbuffer_alloc(file)) {
+		if (jpg_fbuffer_alloc(fh)) {
 			res = -ENOMEM;
 			goto jpgreqbuf_unlock_and_return;
 		}
@@ -1746,7 +1703,7 @@
 			ZR_DEVNAME(zr), *frame);
 
 		mutex_lock(&zr->resource_lock);
-		res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_COMPRESS);
+		res = jpg_qbuf(fh, *frame, BUZ_MODE_MOTION_COMPRESS);
 		mutex_unlock(&zr->resource_lock);
 
 		return res;
@@ -1760,7 +1717,7 @@
 			ZR_DEVNAME(zr), *frame);
 
 		mutex_lock(&zr->resource_lock);
-		res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_DECOMPRESS);
+		res = jpg_qbuf(fh, *frame, BUZ_MODE_MOTION_DECOMPRESS);
 		mutex_unlock(&zr->resource_lock);
 
 		return res;
@@ -1781,7 +1738,7 @@
 				ZR_DEVNAME(zr), __func__);
 			res = -EINVAL;
 		} else {
-			res = jpg_sync(file, bsync);
+			res = jpg_sync(fh, bsync);
 		}
 		mutex_unlock(&zr->resource_lock);
 
@@ -1876,7 +1833,7 @@
 	/* The next mmap will map the V4L buffers */
 	map_mode_raw(fh);
 
-	if (v4l_fbuffer_alloc(file)) {
+	if (v4l_fbuffer_alloc(fh)) {
 		res = -ENOMEM;
 		goto v4l1reqbuf_unlock_and_return;
 	}
@@ -2168,14 +2125,10 @@
 			fmt->fmt.win.clipcount,
 			fmt->fmt.win.bitmap);
 	mutex_lock(&zr->resource_lock);
-	res = setup_window(file, fmt->fmt.win.w.left,
-			fmt->fmt.win.w.top,
-			fmt->fmt.win.w.width,
-			fmt->fmt.win.w.height,
-			(struct v4l2_clip __user *)
-			fmt->fmt.win.clips,
-			fmt->fmt.win.clipcount,
-			fmt->fmt.win.bitmap);
+	res = setup_window(fh, fmt->fmt.win.w.left, fmt->fmt.win.w.top,
+			   fmt->fmt.win.w.width, fmt->fmt.win.w.height,
+			   (struct v4l2_clip __user *)fmt->fmt.win.clips,
+			   fmt->fmt.win.clipcount, fmt->fmt.win.bitmap);
 	mutex_unlock(&zr->resource_lock);
 	return res;
 }
@@ -2363,9 +2316,8 @@
 	}
 
 	mutex_lock(&zr->resource_lock);
-	res = setup_fbuffer(file, fb->base, &zoran_formats[i],
-				fb->fmt.width, fb->fmt.height,
-				fb->fmt.bytesperline);
+	res = setup_fbuffer(fh, fb->base, &zoran_formats[i], fb->fmt.width,
+			    fb->fmt.height, fb->fmt.bytesperline);
 	mutex_unlock(&zr->resource_lock);
 
 	return res;
@@ -2378,7 +2330,7 @@
 	int res;
 
 	mutex_lock(&zr->resource_lock);
-	res = setup_overlay(file, on);
+	res = setup_overlay(fh, on);
 	mutex_unlock(&zr->resource_lock);
 
 	return res;
@@ -2425,7 +2377,7 @@
 		map_mode_raw(fh);
 		fh->buffers.num_buffers = req->count;
 
-		if (v4l_fbuffer_alloc(file)) {
+		if (v4l_fbuffer_alloc(fh)) {
 			res = -ENOMEM;
 			goto v4l2reqbuf_unlock_and_return;
 		}
@@ -2442,7 +2394,7 @@
 		fh->buffers.num_buffers = req->count;
 		fh->buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings);
 
-		if (jpg_fbuffer_alloc(file)) {
+		if (jpg_fbuffer_alloc(fh)) {
 			res = -ENOMEM;
 			goto v4l2reqbuf_unlock_and_return;
 		}
@@ -2491,7 +2443,7 @@
 			goto qbuf_unlock_and_return;
 		}
 
-		res = zoran_v4l_queue_frame(file, buf->index);
+		res = zoran_v4l_queue_frame(fh, buf->index);
 		if (res)
 			goto qbuf_unlock_and_return;
 		if (!zr->v4l_memgrab_active && fh->buffers.active == ZORAN_LOCKED)
@@ -2516,8 +2468,7 @@
 			goto qbuf_unlock_and_return;
 		}
 
-		res = zoran_jpg_queue_frame(file, buf->index,
-					codec_mode);
+		res = zoran_jpg_queue_frame(fh, buf->index, codec_mode);
 		if (res != 0)
 			goto qbuf_unlock_and_return;
 		if (zr->codec_mode == BUZ_MODE_IDLE &&
@@ -2563,7 +2514,7 @@
 			res = -EAGAIN;
 			goto dqbuf_unlock_and_return;
 		}
-		res = v4l_sync(file, num);
+		res = v4l_sync(fh, num);
 		if (res)
 			goto dqbuf_unlock_and_return;
 		zr->v4l_sync_tail++;
@@ -2595,7 +2546,7 @@
 			res = -EAGAIN;
 			goto dqbuf_unlock_and_return;
 		}
-		res = jpg_sync(file, &bs);
+		res = jpg_sync(fh, &bs);
 		if (res)
 			goto dqbuf_unlock_and_return;
 		res = zoran_v4l2_buffer_status(fh, buf, bs.frame);
@@ -2722,7 +2673,7 @@
 		if (zr->jpg_buffers.active == ZORAN_FREE)
 			goto strmoff_unlock_and_return;
 
-		res = jpg_qbuf(file, -1,
+		res = jpg_qbuf(fh, -1,
 			     (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ?
 			     BUZ_MODE_MOTION_COMPRESS :
 			     BUZ_MODE_MOTION_DECOMPRESS);
@@ -3185,8 +3136,7 @@
 zoran_vm_close (struct vm_area_struct *vma)
 {
 	struct zoran_mapping *map = vma->vm_private_data;
-	struct file *file = map->file;
-	struct zoran_fh *fh = file->private_data;
+	struct zoran_fh *fh = map->file->private_data;
 	struct zoran *zr = fh->zr;
 	int i;
 
@@ -3222,14 +3172,14 @@
 			zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE;
 			spin_unlock_irqrestore(&zr->spinlock, flags);
 		}
-		v4l_fbuffer_free(file);
+		v4l_fbuffer_free(fh);
 	} else {
 		if (fh->buffers.active != ZORAN_FREE) {
-			jpg_qbuf(file, -1, zr->codec_mode);
+			jpg_qbuf(fh, -1, zr->codec_mode);
 			zr->jpg_buffers.allocated = 0;
 			zr->jpg_buffers.active = fh->buffers.active = ZORAN_FREE;
 		}
-		jpg_fbuffer_free(file);
+		jpg_fbuffer_free(fh);
 	}
 
 	mutex_unlock(&zr->resource_lock);