提交 337f9d20 编写于 作者: T Trent Piepho 提交者: Mauro Carvalho Chehab

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: NTrent Piepho <xyzzy@speakeasy.org>
Signed-off-by: NMauro Carvalho Chehab <mchehab@redhat.com>
上级 19c96e4b
...@@ -655,8 +655,6 @@ static long __video_do_ioctl(struct file *file, ...@@ -655,8 +655,6 @@ static long __video_do_ioctl(struct file *file,
if (cmd == VIDIOCGMBUF) { if (cmd == VIDIOCGMBUF) {
struct video_mbuf *p = arg; struct video_mbuf *p = arg;
memset(p, 0, sizeof(*p));
if (!ops->vidiocgmbuf) if (!ops->vidiocgmbuf)
return ret; return ret;
ret = ops->vidiocgmbuf(file, fh, p); ret = ops->vidiocgmbuf(file, fh, p);
...@@ -683,7 +681,6 @@ static long __video_do_ioctl(struct file *file, ...@@ -683,7 +681,6 @@ static long __video_do_ioctl(struct file *file,
case VIDIOC_QUERYCAP: case VIDIOC_QUERYCAP:
{ {
struct v4l2_capability *cap = (struct v4l2_capability *)arg; struct v4l2_capability *cap = (struct v4l2_capability *)arg;
memset(cap, 0, sizeof(*cap));
if (!ops->vidioc_querycap) if (!ops->vidioc_querycap)
break; break;
...@@ -1367,7 +1364,6 @@ static long __video_do_ioctl(struct file *file, ...@@ -1367,7 +1364,6 @@ static long __video_do_ioctl(struct file *file,
if (!ops->vidioc_g_audio) if (!ops->vidioc_g_audio)
break; break;
memset(p, 0, sizeof(*p));
ret = ops->vidioc_g_audio(file, fh, p); ret = ops->vidioc_g_audio(file, fh, p);
if (!ret) if (!ret)
dbgarg(cmd, "index=%d, name=%s, capability=0x%x, " dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
...@@ -1409,7 +1405,7 @@ static long __video_do_ioctl(struct file *file, ...@@ -1409,7 +1405,7 @@ static long __video_do_ioctl(struct file *file,
if (!ops->vidioc_g_audout) if (!ops->vidioc_g_audout)
break; break;
dbgarg(cmd, "Enum for index=%d\n", p->index);
ret = ops->vidioc_g_audout(file, fh, p); ret = ops->vidioc_g_audout(file, fh, p);
if (!ret) if (!ret)
dbgarg2("index=%d, name=%s, capability=%d, " dbgarg2("index=%d, name=%s, capability=%d, "
...@@ -1506,8 +1502,6 @@ static long __video_do_ioctl(struct file *file, ...@@ -1506,8 +1502,6 @@ static long __video_do_ioctl(struct file *file,
if (!ops->vidioc_g_jpegcomp) if (!ops->vidioc_g_jpegcomp)
break; break;
memset(p, 0, sizeof(*p));
ret = ops->vidioc_g_jpegcomp(file, fh, p); ret = ops->vidioc_g_jpegcomp(file, fh, p);
if (!ret) if (!ret)
dbgarg(cmd, "quality=%d, APPn=%d, " dbgarg(cmd, "quality=%d, APPn=%d, "
...@@ -1873,13 +1867,7 @@ long video_ioctl2(struct file *file, ...@@ -1873,13 +1867,7 @@ long video_ioctl2(struct file *file,
cmd == VIDIOC_TRY_EXT_CTRLS); cmd == VIDIOC_TRY_EXT_CTRLS);
/* Copy arguments into temp kernel buffer */ /* Copy arguments into temp kernel buffer */
switch (_IOC_DIR(cmd)) { if (_IOC_DIR(cmd) != _IOC_NONE) {
case _IOC_NONE:
parg = NULL;
break;
case _IOC_READ:
case _IOC_WRITE:
case (_IOC_WRITE | _IOC_READ):
if (_IOC_SIZE(cmd) <= sizeof(sbuf)) { if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
parg = sbuf; parg = sbuf;
} else { } else {
...@@ -1900,8 +1888,10 @@ long video_ioctl2(struct file *file, ...@@ -1900,8 +1888,10 @@ long video_ioctl2(struct file *file,
/* zero out anything we don't copy from userspace */ /* zero out anything we don't copy from userspace */
if (n < _IOC_SIZE(cmd)) if (n < _IOC_SIZE(cmd))
memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n); memset((u8 *)parg + n, 0, _IOC_SIZE(cmd) - n);
} else {
/* read-only ioctl */
memset(parg, 0, _IOC_SIZE(cmd));
} }
break;
} }
if (is_ext_ctrl) { if (is_ext_ctrl) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册