diff options
author | Trent Piepho <xyzzy@speakeasy.org> | 2009-04-30 20:03:34 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-05-09 17:50:54 -0400 |
commit | 171f48e254339548a910867c7a77c4a4d16e7e16 (patch) | |
tree | 6a1fd40b20b6e7cc2116e1a567aa857ab56dd099 /drivers/media | |
parent | cb1287a82281ab3ddb0768250a46603977075b91 (diff) |
V4L/DVB (11660): zoran: fix bug when enumerating format -1
If someone requests a format at fmt->index == (unsigned)-1 and the first
format in the array doesn't have the requested type then num will still be
-1 when it's compared to fmt->index and there will appear to be a match.
Restructure the loop so this can't happen. It's simpler this way too. The
unnecessary check for (unsigned)fmt->index < 0 found by Roel Kluin
<roel.kluin@gmail.com> is removed this way too.
Signed-off-by: Trent Piepho <xyzzy@speakeasy.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/video/zoran/zoran_driver.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c index 092333b1c34f..643cccaa1aab 100644 --- a/drivers/media/video/zoran/zoran_driver.c +++ b/drivers/media/video/zoran/zoran_driver.c | |||
@@ -1863,22 +1863,20 @@ static int zoran_querycap(struct file *file, void *__fh, struct v4l2_capability | |||
1863 | 1863 | ||
1864 | static int zoran_enum_fmt(struct zoran *zr, struct v4l2_fmtdesc *fmt, int flag) | 1864 | static int zoran_enum_fmt(struct zoran *zr, struct v4l2_fmtdesc *fmt, int flag) |
1865 | { | 1865 | { |
1866 | int num = -1, i; | 1866 | unsigned int num, i; |
1867 | 1867 | ||
1868 | for (i = 0; i < NUM_FORMATS; i++) { | 1868 | for (num = i = 0; i < NUM_FORMATS; i++) { |
1869 | if (zoran_formats[i].flags & flag) | 1869 | if (zoran_formats[i].flags & flag && num++ == fmt->index) { |
1870 | num++; | 1870 | strncpy(fmt->description, zoran_formats[i].name, |
1871 | if (num == fmt->index) | 1871 | sizeof(fmt->description) - 1); |
1872 | break; | 1872 | /* fmt struct pre-zeroed, so adding '\0' not neeed */ |
1873 | fmt->pixelformat = zoran_formats[i].fourcc; | ||
1874 | if (zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED) | ||
1875 | fmt->flags |= V4L2_FMT_FLAG_COMPRESSED; | ||
1876 | return 0; | ||
1877 | } | ||
1873 | } | 1878 | } |
1874 | if (fmt->index < 0 /* late, but not too late */ || i == NUM_FORMATS) | 1879 | return -EINVAL; |
1875 | return -EINVAL; | ||
1876 | |||
1877 | strncpy(fmt->description, zoran_formats[i].name, sizeof(fmt->description)-1); | ||
1878 | fmt->pixelformat = zoran_formats[i].fourcc; | ||
1879 | if (zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED) | ||
1880 | fmt->flags |= V4L2_FMT_FLAG_COMPRESSED; | ||
1881 | return 0; | ||
1882 | } | 1880 | } |
1883 | 1881 | ||
1884 | static int zoran_enum_fmt_vid_cap(struct file *file, void *__fh, | 1882 | static int zoran_enum_fmt_vid_cap(struct file *file, void *__fh, |