[media] v4l: Validate fields in the core code for subdev EDID ioctls
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Wed, 29 Jan 2014 13:07:13 +0000 (10:07 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Sun, 25 May 2014 15:48:33 +0000 (12:48 -0300)
The subdev EDID ioctls receive a pad field that must reference an
existing pad and an EDID field that must point to a buffer. Validate
both fields in the core code instead of duplicating validation in all
drivers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/i2c/ad9389b.c
drivers/media/i2c/adv7511.c
drivers/media/i2c/adv7604.c
drivers/media/i2c/adv7842.c
drivers/media/v4l2-core/v4l2-subdev.c

index f00b3dd2b457ea17c19aa0d6bc46a4030042e391..fada17566205015d32d5923ed068d21efcc6ae5a 100644 (file)
@@ -682,8 +682,6 @@ static int ad9389b_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
                return -EINVAL;
        if (edid->blocks == 0 || edid->blocks > 256)
                return -EINVAL;
-       if (!edid->edid)
-               return -EINVAL;
        if (!state->edid.segments) {
                v4l2_dbg(1, debug, sd, "EDID segment 0 not found\n");
                return -ENODATA;
index d77a1db4f94d51fe3b5e0488e6d7cdb8da383e0c..f98acf4aafd43b16f0a3178b6541f5409eca20b3 100644 (file)
@@ -783,8 +783,6 @@ static int adv7511_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
                return -EINVAL;
        if ((edid->blocks == 0) || (edid->blocks > 256))
                return -EINVAL;
-       if (!edid->edid)
-               return -EINVAL;
        if (!state->edid.segments) {
                v4l2_dbg(1, debug, sd, "EDID segment 0 not found\n");
                return -ENODATA;
index 98cc5407f1b12935f817f8f63902dada77d1355c..338baa4c23ef58ece1dad425b67a367edc28e10c 100644 (file)
@@ -1673,8 +1673,6 @@ static int adv7604_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
                return -EINVAL;
        if (edid->start_block == 1)
                edid->blocks = 1;
-       if (!edid->edid)
-               return -EINVAL;
 
        if (edid->blocks > state->edid.blocks)
                edid->blocks = state->edid.blocks;
@@ -1761,8 +1759,6 @@ static int adv7604_set_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
                edid->blocks = 2;
                return -E2BIG;
        }
-       if (!edid->edid)
-               return -EINVAL;
 
        v4l2_dbg(2, debug, sd, "%s: write EDID pad %d, edid.present = 0x%x\n",
                        __func__, edid->pad, state->edid.present);
index d85e125aa8d816d9c593113b648467d728d41a4c..0d554919cdd52726f52deda278414aa62bb6e47c 100644 (file)
@@ -2036,8 +2036,6 @@ static int adv7842_get_edid(struct v4l2_subdev *sd, struct v4l2_edid *edid)
                return -EINVAL;
        if (edid->start_block == 1)
                edid->blocks = 1;
-       if (!edid->edid)
-               return -EINVAL;
 
        switch (edid->pad) {
        case ADV7842_EDID_PORT_A:
@@ -2072,8 +2070,6 @@ static int adv7842_set_edid(struct v4l2_subdev *sd, struct v4l2_edid *e)
                return -EINVAL;
        if (e->blocks > 2)
                return -E2BIG;
-       if (!e->edid)
-               return -EINVAL;
 
        /* todo, per edid */
        state->aspect_ratio = v4l2_calc_aspect_ratio(e->edid[0x15],
index db126dbc19c9491796219ada75e3445ac562ace1..058c1a6e839275ce1e61cad44946b5c30093c0ad 100644 (file)
@@ -361,11 +361,27 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
                        sd, pad, set_selection, subdev_fh, sel);
        }
 
-       case VIDIOC_G_EDID:
-               return v4l2_subdev_call(sd, pad, get_edid, arg);
+       case VIDIOC_G_EDID: {
+               struct v4l2_subdev_edid *edid = arg;
 
-       case VIDIOC_S_EDID:
-               return v4l2_subdev_call(sd, pad, set_edid, arg);
+               if (edid->pad >= sd->entity.num_pads)
+                       return -EINVAL;
+               if (edid->blocks && edid->edid == NULL)
+                       return -EINVAL;
+
+               return v4l2_subdev_call(sd, pad, get_edid, edid);
+       }
+
+       case VIDIOC_S_EDID: {
+               struct v4l2_subdev_edid *edid = arg;
+
+               if (edid->pad >= sd->entity.num_pads)
+                       return -EINVAL;
+               if (edid->blocks && edid->edid == NULL)
+                       return -EINVAL;
+
+               return v4l2_subdev_call(sd, pad, set_edid, edid);
+       }
 
        case VIDIOC_SUBDEV_DV_TIMINGS_CAP: {
                struct v4l2_dv_timings_cap *cap = arg;