Index: gspca.c
===================================================================
--- gspca.c	(revision 435)
+++ gspca.c	(working copy)
@@ -646,44 +646,6 @@
 	gspca_dev->pixfmt = gspca_dev->cam.cam_mode[i].pixelformat;
 }
 
-static int wxh_to_mode(struct gspca_dev *gspca_dev,
-			int width, int height)
-{
-	int i;
-
-	for (i = gspca_dev->cam.nmodes; --i > 0; ) {
-		if (width >= gspca_dev->cam.cam_mode[i].width
-		    && height >= gspca_dev->cam.cam_mode[i].height)
-			break;
-	}
-	return i;
-}
-
-/*
- * search a mode with the right pixel format
- */
-static int gspca_get_mode(struct gspca_dev *gspca_dev,
-			int mode,
-			int pixfmt)
-{
-	int modeU, modeD;
-
-	modeU = modeD = mode;
-	while ((modeU < gspca_dev->cam.nmodes) || modeD >= 0) {
-		if (--modeD >= 0) {
-			if (gspca_dev->cam.cam_mode[modeD].pixelformat
-								== pixfmt)
-				return modeD;
-		}
-		if (++modeU < gspca_dev->cam.nmodes) {
-			if (gspca_dev->cam.cam_mode[modeU].pixelformat
-								== pixfmt)
-				return modeU;
-		}
-	}
-	return -EINVAL;
-}
-
 static int vidioc_enum_fmt_vid_cap(struct file *file, void  *priv,
 				struct v4l2_fmtdesc *fmtdesc)
 {
@@ -742,34 +704,30 @@
 static int try_fmt_vid_cap(struct gspca_dev *gspca_dev,
 			struct v4l2_format *fmt)
 {
-	int w, h, mode, mode2;
+	int width, height, i, mode = -EINVAL;;
 
 	if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
 		return -EINVAL;
-	w = fmt->fmt.pix.width;
-	h = fmt->fmt.pix.height;
+	width = fmt->fmt.pix.width;
+	height = fmt->fmt.pix.height;
 
 #ifdef GSPCA_DEBUG
 	if (gspca_debug & D_CONF)
-		PDEBUG_MODE("try fmt cap", fmt->fmt.pix.pixelformat, w, h);
+		PDEBUG_MODE("try fmt cap", fmt->fmt.pix.pixelformat, width, height);
 #endif
-	/* search the closest mode for width and height */
-	mode = wxh_to_mode(gspca_dev, w, h);
-
-	/* OK if right palette */
-	if (gspca_dev->cam.cam_mode[mode].pixelformat
-						!= fmt->fmt.pix.pixelformat) {
-
-		/* else, search the closest mode with the same pixel format */
-		mode2 = gspca_get_mode(gspca_dev, mode,
-					fmt->fmt.pix.pixelformat);
-		if (mode2 >= 0)
-			mode = mode2;
-/*		else
-			;		 * no chance, return this mode */
+	
+	/* search the closest mode for width and height with same pixelformat */
+	for (i = gspca_dev->cam.nmodes; --i >= 0; ) {
+		if (width >= gspca_dev->cam.cam_mode[i].width
+				  && height >= gspca_dev->cam.cam_mode[i].height
+				  && fmt->fmt.pix.pixelformat == gspca_dev->cam.cam_mode[i].pixelformat){
+			mode = i;
+			break;
+		}
 	}
-	memcpy(&fmt->fmt.pix, &gspca_dev->cam.cam_mode[mode],
-		sizeof fmt->fmt.pix);
+
+	if (mode >= 0)
+		memcpy(&fmt->fmt.pix, &gspca_dev->cam.cam_mode[mode], sizeof fmt->fmt.pix);
 	return mode;			/* used when s_fmt */
 }
 
