aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrent Piepho <xyzzy@speakeasy.org>2009-03-03 23:21:02 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-03-30 11:43:05 -0400
commit337f9d205972bfe1cb7982384fd0f4caa4af001d (patch)
treece1f34f16e8a952a4e356e2a40984a30a3f5ab21
parent19c96e4b7d3c80071982a052e4a921c1a39875d9 (diff)
V4L/DVB (10812): v4l2: Zero out read-only ioctls in one place
If an ioctl is read-only then the driver fills in all the fields. Lots of times drivers only care about some fields so it's best if video_ioctl2 takes care of zeroing out the entire structure before handing it to the driver. This saves code in each driver to do it and driver authors often forget. The existing memset code in some of the read-only ioctl handlers can be deleted. Convert a case statement to a single if statement. Deleted a debug line from ENUMAUDOUT that was copy-and-pasted to G_AUDOUT by mistake. Signed-off-by: Trent Piepho <xyzzy@speakeasy.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/video/v4l2-ioctl.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 00c0f76b9b5d..64b4fda08dd5 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -655,8 +655,6 @@ static long __video_do_ioctl(struct file *file,
655 if (cmd == VIDIOCGMBUF) { 655 if (cmd == VIDIOCGMBUF) {
656 struct video_mbuf *p = arg; 656 struct video_mbuf *p = arg;
657 657
658 memset(p, 0, sizeof(*p));
659
660 if (!ops->vidiocgmbuf) 658 if (!ops->vidiocgmbuf)
661 return ret; 659 return ret;
662 ret = ops->vidiocgmbuf(file, fh, p); 660 ret = ops->vidiocgmbuf(file, fh, p);
@@ -683,7 +681,6 @@ static long __video_do_ioctl(struct file *file,
683 case VIDIOC_QUERYCAP: 681 case VIDIOC_QUERYCAP:
684 { 682 {
685 struct v4l2_capability *cap = (struct v4l2_capability *)arg; 683 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
686 memset(cap, 0, sizeof(*cap));
687 684
688 if (!ops->vidioc_querycap) 685 if (!ops->vidioc_querycap)
689 break; 686 break;
@@ -1367,7 +1364,6 @@ static long __video_do_ioctl(struct file *file,
1367 if (!ops->vidioc_g_audio) 1364 if (!ops->vidioc_g_audio)
1368 break; 1365 break;
1369 1366
1370 memset(p, 0, sizeof(*p));
1371 ret = ops->vidioc_g_audio(file, fh, p); 1367 ret = ops->vidioc_g_audio(file, fh, p);
1372 if (!ret) 1368 if (!ret)
1373 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, " 1369 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
@@ -1409,7 +1405,7 @@ static long __video_do_ioctl(struct file *file,
1409 1405
1410 if (!ops->vidioc_g_audout) 1406 if (!ops->vidioc_g_audout)
1411 break; 1407 break;
1412 dbgarg(cmd, "Enum for index=%d\n", p->index); 1408
1413 ret = ops->vidioc_g_audout(file, fh, p); 1409 ret = ops->vidioc_g_audout(file, fh, p);
1414 if (!ret) 1410 if (!ret)
1415 dbgarg2("index=%d, name=%s, capability=%d, " 1411 dbgarg2("index=%d, name=%s, capability=%d, "
@@ -1506,8 +1502,6 @@ static long __video_do_ioctl(struct file *file,
1506 if (!ops->vidioc_g_jpegcomp) 1502 if (!ops->vidioc_g_jpegcomp)
1507 break; 1503 break;
1508 1504
1509 memset(p, 0, sizeof(*p));
1510
1511 ret = ops->vidioc_g_jpegcomp(file, fh, p); 1505 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1512 if (!ret) 1506 if (!ret)
1513 dbgarg(cmd, "quality=%d, APPn=%d, " 1507 dbgarg(cmd, "quality=%d, APPn=%d, "
@@ -1873,13 +1867,7 @@ long video_ioctl2(struct file *file,
1873 cmd == VIDIOC_TRY_EXT_CTRLS); 1867 cmd == VIDIOC_TRY_EXT_CTRLS);
1874 1868
1875 /* Copy arguments into temp kernel buffer */ 1869 /* Copy arguments into temp kernel buffer */
1876 switch (_IOC_DIR(cmd)) { 1870 if (_IOC_DIR(cmd) != _IOC_NONE) {
1877 case _IOC_NONE:
1878 parg = NULL;
1879 break;
1880 case _IOC_READ:
1881 case _IOC_WRITE:
1882 case (_IOC_WRITE | _IOC_READ):
1883 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) { 1871 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1884 parg = sbuf; 1872 parg = sbuf;
1885 } else { 1873 } else {
@@ -1900,8 +1888,10 @@ long video_ioctl2(struct file *file,
1900 /* zero out anything we don't copy from userspace */ 1888 /* zero out anything we don't copy from userspace */
1901 if (n < _IOC_SIZE(cmd)) 1889 if (n < _IOC_SIZE(cmd))
1902 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n); 1890 memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
1891 } else {
1892 /* read-only ioctl */
1893 memset(parg, 0, _IOC_SIZE(cmd));
1903 } 1894 }
1904 break;
1905 } 1895 }
1906 1896
1907 if (is_ext_ctrl) { 1897 if (is_ext_ctrl) {