Commit b225e398 authored by Sakari Ailus's avatar Sakari Ailus Committed by Mauro Carvalho Chehab

[media] v4l: subdev: Unify argument validation across IOCTLs

Separate validation of different argument types. There's no reason to do
this separately for every IOCTL.
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent 6c5bba9b
...@@ -126,6 +126,55 @@ static int subdev_close(struct file *file) ...@@ -126,6 +126,55 @@ static int subdev_close(struct file *file)
return 0; return 0;
} }
static int check_format(struct v4l2_subdev *sd,
struct v4l2_subdev_format *format)
{
if (format->which != V4L2_SUBDEV_FORMAT_TRY &&
format->which != V4L2_SUBDEV_FORMAT_ACTIVE)
return -EINVAL;
if (format->pad >= sd->entity.num_pads)
return -EINVAL;
return 0;
}
static int check_crop(struct v4l2_subdev *sd, struct v4l2_subdev_crop *crop)
{
if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
return -EINVAL;
if (crop->pad >= sd->entity.num_pads)
return -EINVAL;
return 0;
}
static int check_selection(struct v4l2_subdev *sd,
struct v4l2_subdev_selection *sel)
{
if (sel->which != V4L2_SUBDEV_FORMAT_TRY &&
sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
return -EINVAL;
if (sel->pad >= sd->entity.num_pads)
return -EINVAL;
return 0;
}
static int check_edid(struct v4l2_subdev *sd, struct v4l2_subdev_edid *edid)
{
if (edid->pad >= sd->entity.num_pads)
return -EINVAL;
if (edid->blocks && edid->edid == NULL)
return -EINVAL;
return 0;
}
static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
{ {
struct video_device *vdev = video_devdata(file); struct video_device *vdev = video_devdata(file);
...@@ -134,6 +183,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -134,6 +183,7 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
#if defined(CONFIG_VIDEO_V4L2_SUBDEV_API) #if defined(CONFIG_VIDEO_V4L2_SUBDEV_API)
struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh); struct v4l2_subdev_fh *subdev_fh = to_v4l2_subdev_fh(vfh);
#endif #endif
int rval;
switch (cmd) { switch (cmd) {
case VIDIOC_QUERYCTRL: case VIDIOC_QUERYCTRL:
...@@ -206,12 +256,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -206,12 +256,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOC_SUBDEV_G_FMT: { case VIDIOC_SUBDEV_G_FMT: {
struct v4l2_subdev_format *format = arg; struct v4l2_subdev_format *format = arg;
if (format->which != V4L2_SUBDEV_FORMAT_TRY && rval = check_format(sd, format);
format->which != V4L2_SUBDEV_FORMAT_ACTIVE) if (rval)
return -EINVAL; return rval;
if (format->pad >= sd->entity.num_pads)
return -EINVAL;
return v4l2_subdev_call(sd, pad, get_fmt, subdev_fh, format); return v4l2_subdev_call(sd, pad, get_fmt, subdev_fh, format);
} }
...@@ -219,12 +266,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -219,12 +266,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOC_SUBDEV_S_FMT: { case VIDIOC_SUBDEV_S_FMT: {
struct v4l2_subdev_format *format = arg; struct v4l2_subdev_format *format = arg;
if (format->which != V4L2_SUBDEV_FORMAT_TRY && rval = check_format(sd, format);
format->which != V4L2_SUBDEV_FORMAT_ACTIVE) if (rval)
return -EINVAL; return rval;
if (format->pad >= sd->entity.num_pads)
return -EINVAL;
return v4l2_subdev_call(sd, pad, set_fmt, subdev_fh, format); return v4l2_subdev_call(sd, pad, set_fmt, subdev_fh, format);
} }
...@@ -232,14 +276,10 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -232,14 +276,10 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOC_SUBDEV_G_CROP: { case VIDIOC_SUBDEV_G_CROP: {
struct v4l2_subdev_crop *crop = arg; struct v4l2_subdev_crop *crop = arg;
struct v4l2_subdev_selection sel; struct v4l2_subdev_selection sel;
int rval;
if (crop->which != V4L2_SUBDEV_FORMAT_TRY && rval = check_crop(sd, crop);
crop->which != V4L2_SUBDEV_FORMAT_ACTIVE) if (rval)
return -EINVAL; return rval;
if (crop->pad >= sd->entity.num_pads)
return -EINVAL;
rval = v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop); rval = v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
if (rval != -ENOIOCTLCMD) if (rval != -ENOIOCTLCMD)
...@@ -261,14 +301,10 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -261,14 +301,10 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOC_SUBDEV_S_CROP: { case VIDIOC_SUBDEV_S_CROP: {
struct v4l2_subdev_crop *crop = arg; struct v4l2_subdev_crop *crop = arg;
struct v4l2_subdev_selection sel; struct v4l2_subdev_selection sel;
int rval;
if (crop->which != V4L2_SUBDEV_FORMAT_TRY &&
crop->which != V4L2_SUBDEV_FORMAT_ACTIVE)
return -EINVAL;
if (crop->pad >= sd->entity.num_pads) rval = check_crop(sd, crop);
return -EINVAL; if (rval)
return rval;
rval = v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop); rval = v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
if (rval != -ENOIOCTLCMD) if (rval != -ENOIOCTLCMD)
...@@ -339,12 +375,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -339,12 +375,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOC_SUBDEV_G_SELECTION: { case VIDIOC_SUBDEV_G_SELECTION: {
struct v4l2_subdev_selection *sel = arg; struct v4l2_subdev_selection *sel = arg;
if (sel->which != V4L2_SUBDEV_FORMAT_TRY && rval = check_selection(sd, sel);
sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) if (rval)
return -EINVAL; return rval;
if (sel->pad >= sd->entity.num_pads)
return -EINVAL;
return v4l2_subdev_call( return v4l2_subdev_call(
sd, pad, get_selection, subdev_fh, sel); sd, pad, get_selection, subdev_fh, sel);
...@@ -353,12 +386,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -353,12 +386,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOC_SUBDEV_S_SELECTION: { case VIDIOC_SUBDEV_S_SELECTION: {
struct v4l2_subdev_selection *sel = arg; struct v4l2_subdev_selection *sel = arg;
if (sel->which != V4L2_SUBDEV_FORMAT_TRY && rval = check_selection(sd, sel);
sel->which != V4L2_SUBDEV_FORMAT_ACTIVE) if (rval)
return -EINVAL; return rval;
if (sel->pad >= sd->entity.num_pads)
return -EINVAL;
return v4l2_subdev_call( return v4l2_subdev_call(
sd, pad, set_selection, subdev_fh, sel); sd, pad, set_selection, subdev_fh, sel);
...@@ -367,10 +397,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -367,10 +397,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOC_G_EDID: { case VIDIOC_G_EDID: {
struct v4l2_subdev_edid *edid = arg; struct v4l2_subdev_edid *edid = arg;
if (edid->pad >= sd->entity.num_pads) rval = check_edid(sd, edid);
return -EINVAL; if (rval)
if (edid->blocks && edid->edid == NULL) return rval;
return -EINVAL;
return v4l2_subdev_call(sd, pad, get_edid, edid); return v4l2_subdev_call(sd, pad, get_edid, edid);
} }
...@@ -378,10 +407,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) ...@@ -378,10 +407,9 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
case VIDIOC_S_EDID: { case VIDIOC_S_EDID: {
struct v4l2_subdev_edid *edid = arg; struct v4l2_subdev_edid *edid = arg;
if (edid->pad >= sd->entity.num_pads) rval = check_edid(sd, edid);
return -EINVAL; if (rval)
if (edid->blocks && edid->edid == NULL) return rval;
return -EINVAL;
return v4l2_subdev_call(sd, pad, set_edid, edid); return v4l2_subdev_call(sd, pad, set_edid, edid);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment