Re: [PATCH v2 27/48] v4l: Validate fields in the core code for subdev EDID ioctls

2014-03-11 Thread Sakari Ailus
On Tue, Mar 11, 2014 at 12:15:38AM +0100, Laurent Pinchart wrote:
 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.pinch...@ideasonboard.com

Acked-by: Sakari Ailus sakari.ai...@linux.intel.com

-- 
Sakari Ailus
e-mail: sakari.ai...@iki.fi XMPP: sai...@retiisi.org.uk
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 27/48] v4l: Validate fields in the core code for subdev EDID ioctls

2014-03-11 Thread Hans Verkuil
On 03/11/14 00:15, Laurent Pinchart wrote:
 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.pinch...@ideasonboard.com
 ---
  drivers/media/i2c/ad9389b.c   |  2 --
  drivers/media/i2c/adv7511.c   |  2 --
  drivers/media/i2c/adv7604.c   |  4 
  drivers/media/i2c/adv7842.c   |  4 
  drivers/media/v4l2-core/v4l2-subdev.c | 24 
  5 files changed, 20 insertions(+), 16 deletions(-)
 
 diff --git a/drivers/media/i2c/ad9389b.c b/drivers/media/i2c/ad9389b.c
 index 4cdff9e..5b78828 100644
 --- a/drivers/media/i2c/ad9389b.c
 +++ b/drivers/media/i2c/ad9389b.c
 @@ -683,8 +683,6 @@ static int ad9389b_get_edid(struct v4l2_subdev *sd,
   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;
 diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c
 index de7ddf5..ff1c2cd 100644
 --- a/drivers/media/i2c/adv7511.c
 +++ b/drivers/media/i2c/adv7511.c
 @@ -784,8 +784,6 @@ static int adv7511_get_edid(struct v4l2_subdev *sd,
   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;
 diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
 index 71c8570..de3db42 100644
 --- a/drivers/media/i2c/adv7604.c
 +++ b/drivers/media/i2c/adv7604.c
 @@ -1673,8 +1673,6 @@ static int adv7604_get_edid(struct v4l2_subdev *sd, 
 struct v4l2_subdev_edid *edi
   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_subdev_edid *edi
   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);
 diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
 index 7fd9325..33558c8 100644
 --- a/drivers/media/i2c/adv7842.c
 +++ b/drivers/media/i2c/adv7842.c
 @@ -2035,8 +2035,6 @@ static int adv7842_get_edid(struct v4l2_subdev *sd, 
 struct v4l2_subdev_edid *edi
   return -EINVAL;
   if (edid-start_block == 1)
   edid-blocks = 1;
 - if (!edid-edid)
 - return -EINVAL;
  
   switch (edid-pad) {
   case ADV7842_EDID_PORT_A:
 @@ -2071,8 +2069,6 @@ static int adv7842_set_edid(struct v4l2_subdev *sd, 
 struct v4l2_subdev_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],
 diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
 b/drivers/media/v4l2-core/v4l2-subdev.c
 index 853fb84..9fff1eb 100644
 --- a/drivers/media/v4l2-core/v4l2-subdev.c
 +++ b/drivers/media/v4l2-core/v4l2-subdev.c
 @@ -349,11 +349,27 @@ static long subdev_do_ioctl(struct file *file, unsigned 
 int cmd, void *arg)
   sd, pad, set_selection, subdev_fh, sel);
   }
  
 - case VIDIOC_SUBDEV_G_EDID:
 - return v4l2_subdev_call(sd, pad, get_edid, arg);
 + case VIDIOC_SUBDEV_G_EDID: {
 + struct v4l2_subdev_edid *edid = arg;
  
 - case VIDIOC_SUBDEV_S_EDID:
 - return v4l2_subdev_call(sd, pad, set_edid, arg);
 + if (edid-pad = sd-entity.num_pads)
 + return -EINVAL;
 + if (edid-edid == NULL)
 + return -EINVAL;
 +
 + return v4l2_subdev_call(sd, pad, get_edid, edid);
 + }
 +
 + case VIDIOC_SUBDEV_S_EDID: {
 + struct v4l2_subdev_edid *edid = arg;
 +
 + if (edid-pad = sd-entity.num_pads)
 + return -EINVAL;
 + if (edid-edid == NULL)
 + return -EINVAL;

If edid-blocks == 0, then edid-edid may be NULL. So this should
read:

if (edid-blocks  edid-edid == NULL)

This is true for both G and S_EDID ioctls.

Regards,

Hans

 +
 + return v4l2_subdev_call(sd, pad, set_edid, edid);
 + }
  
   case VIDIOC_SUBDEV_DV_TIMINGS_CAP: {
   struct 

Re: [PATCH v2 27/48] v4l: Validate fields in the core code for subdev EDID ioctls

2014-03-11 Thread Laurent Pinchart
Hi Hans,

On Tuesday 11 March 2014 11:45:09 Hans Verkuil wrote:
 On 03/11/14 00:15, Laurent Pinchart wrote:
  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.pinch...@ideasonboard.com
  ---
  
   drivers/media/i2c/ad9389b.c   |  2 --
   drivers/media/i2c/adv7511.c   |  2 --
   drivers/media/i2c/adv7604.c   |  4 
   drivers/media/i2c/adv7842.c   |  4 
   drivers/media/v4l2-core/v4l2-subdev.c | 24 
   5 files changed, 20 insertions(+), 16 deletions(-)

[snip]

  diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
  b/drivers/media/v4l2-core/v4l2-subdev.c index 853fb84..9fff1eb 100644
  --- a/drivers/media/v4l2-core/v4l2-subdev.c
  +++ b/drivers/media/v4l2-core/v4l2-subdev.c
  @@ -349,11 +349,27 @@ static long subdev_do_ioctl(struct file *file,
  unsigned int cmd, void *arg) 
  sd, pad, set_selection, subdev_fh, sel);
  }
  
  -   case VIDIOC_SUBDEV_G_EDID:
  -   return v4l2_subdev_call(sd, pad, get_edid, arg);
  +   case VIDIOC_SUBDEV_G_EDID: {
  +   struct v4l2_subdev_edid *edid = arg;
  
  -   case VIDIOC_SUBDEV_S_EDID:
  -   return v4l2_subdev_call(sd, pad, set_edid, arg);
  +   if (edid-pad = sd-entity.num_pads)
  +   return -EINVAL;
  +   if (edid-edid == NULL)
  +   return -EINVAL;
  +
  +   return v4l2_subdev_call(sd, pad, get_edid, edid);
  +   }
  +
  +   case VIDIOC_SUBDEV_S_EDID: {
  +   struct v4l2_subdev_edid *edid = arg;
  +
  +   if (edid-pad = sd-entity.num_pads)
  +   return -EINVAL;
  +   if (edid-edid == NULL)
  +   return -EINVAL;
 
 If edid-blocks == 0, then edid-edid may be NULL. So this should
 read:
 
   if (edid-blocks  edid-edid == NULL)

OK, I'll fix that.

 This is true for both G and S_EDID ioctls.

What's the point of G_EDID with blocks == 0 ? Testing whether the ioctl is 
supported ?

  +
  +   return v4l2_subdev_call(sd, pad, set_edid, edid);
  +   }
  
  case VIDIOC_SUBDEV_DV_TIMINGS_CAP: {
  struct v4l2_dv_timings_cap *cap = arg;

-- 
Regards,

Laurent Pinchart

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 27/48] v4l: Validate fields in the core code for subdev EDID ioctls

2014-03-11 Thread Hans Verkuil


On 03/11/14 11:57, Laurent Pinchart wrote:
 Hi Hans,
 
 On Tuesday 11 March 2014 11:45:09 Hans Verkuil wrote:
 On 03/11/14 00:15, Laurent Pinchart wrote:
 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.pinch...@ideasonboard.com
 ---

  drivers/media/i2c/ad9389b.c   |  2 --
  drivers/media/i2c/adv7511.c   |  2 --
  drivers/media/i2c/adv7604.c   |  4 
  drivers/media/i2c/adv7842.c   |  4 
  drivers/media/v4l2-core/v4l2-subdev.c | 24 
  5 files changed, 20 insertions(+), 16 deletions(-)
 
 [snip]
 
 diff --git a/drivers/media/v4l2-core/v4l2-subdev.c
 b/drivers/media/v4l2-core/v4l2-subdev.c index 853fb84..9fff1eb 100644
 --- a/drivers/media/v4l2-core/v4l2-subdev.c
 +++ b/drivers/media/v4l2-core/v4l2-subdev.c
 @@ -349,11 +349,27 @@ static long subdev_do_ioctl(struct file *file,
 unsigned int cmd, void *arg) 
 sd, pad, set_selection, subdev_fh, sel);
 }

 -   case VIDIOC_SUBDEV_G_EDID:
 -   return v4l2_subdev_call(sd, pad, get_edid, arg);
 +   case VIDIOC_SUBDEV_G_EDID: {
 +   struct v4l2_subdev_edid *edid = arg;

 -   case VIDIOC_SUBDEV_S_EDID:
 -   return v4l2_subdev_call(sd, pad, set_edid, arg);
 +   if (edid-pad = sd-entity.num_pads)
 +   return -EINVAL;
 +   if (edid-edid == NULL)
 +   return -EINVAL;
 +
 +   return v4l2_subdev_call(sd, pad, get_edid, edid);
 +   }
 +
 +   case VIDIOC_SUBDEV_S_EDID: {
 +   struct v4l2_subdev_edid *edid = arg;
 +
 +   if (edid-pad = sd-entity.num_pads)
 +   return -EINVAL;
 +   if (edid-edid == NULL)
 +   return -EINVAL;

 If edid-blocks == 0, then edid-edid may be NULL. So this should
 read:

  if (edid-blocks  edid-edid == NULL)
 
 OK, I'll fix that.
 
 This is true for both G and S_EDID ioctls.
 
 What's the point of G_EDID with blocks == 0 ? Testing whether the ioctl is 
 supported ?

Now that you mention it, yes, that would be a good use :-)

But I was thinking that you can call it once with blocks == 0, then the
driver will fill in the real number of blocks and you can use that to
size the edid array correctly.

Regards,

Hans
--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 27/48] v4l: Validate fields in the core code for subdev EDID ioctls

2014-03-10 Thread Laurent Pinchart
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.pinch...@ideasonboard.com
---
 drivers/media/i2c/ad9389b.c   |  2 --
 drivers/media/i2c/adv7511.c   |  2 --
 drivers/media/i2c/adv7604.c   |  4 
 drivers/media/i2c/adv7842.c   |  4 
 drivers/media/v4l2-core/v4l2-subdev.c | 24 
 5 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/drivers/media/i2c/ad9389b.c b/drivers/media/i2c/ad9389b.c
index 4cdff9e..5b78828 100644
--- a/drivers/media/i2c/ad9389b.c
+++ b/drivers/media/i2c/ad9389b.c
@@ -683,8 +683,6 @@ static int ad9389b_get_edid(struct v4l2_subdev *sd,
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;
diff --git a/drivers/media/i2c/adv7511.c b/drivers/media/i2c/adv7511.c
index de7ddf5..ff1c2cd 100644
--- a/drivers/media/i2c/adv7511.c
+++ b/drivers/media/i2c/adv7511.c
@@ -784,8 +784,6 @@ static int adv7511_get_edid(struct v4l2_subdev *sd,
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;
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index 71c8570..de3db42 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -1673,8 +1673,6 @@ static int adv7604_get_edid(struct v4l2_subdev *sd, 
struct v4l2_subdev_edid *edi
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_subdev_edid *edi
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);
diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 7fd9325..33558c8 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -2035,8 +2035,6 @@ static int adv7842_get_edid(struct v4l2_subdev *sd, 
struct v4l2_subdev_edid *edi
return -EINVAL;
if (edid-start_block == 1)
edid-blocks = 1;
-   if (!edid-edid)
-   return -EINVAL;
 
switch (edid-pad) {
case ADV7842_EDID_PORT_A:
@@ -2071,8 +2069,6 @@ static int adv7842_set_edid(struct v4l2_subdev *sd, 
struct v4l2_subdev_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],
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c 
b/drivers/media/v4l2-core/v4l2-subdev.c
index 853fb84..9fff1eb 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -349,11 +349,27 @@ static long subdev_do_ioctl(struct file *file, unsigned 
int cmd, void *arg)
sd, pad, set_selection, subdev_fh, sel);
}
 
-   case VIDIOC_SUBDEV_G_EDID:
-   return v4l2_subdev_call(sd, pad, get_edid, arg);
+   case VIDIOC_SUBDEV_G_EDID: {
+   struct v4l2_subdev_edid *edid = arg;
 
-   case VIDIOC_SUBDEV_S_EDID:
-   return v4l2_subdev_call(sd, pad, set_edid, arg);
+   if (edid-pad = sd-entity.num_pads)
+   return -EINVAL;
+   if (edid-edid == NULL)
+   return -EINVAL;
+
+   return v4l2_subdev_call(sd, pad, get_edid, edid);
+   }
+
+   case VIDIOC_SUBDEV_S_EDID: {
+   struct v4l2_subdev_edid *edid = arg;
+
+   if (edid-pad = sd-entity.num_pads)
+   return -EINVAL;
+   if (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;
-- 
1.8.3.2

--
To unsubscribe from this list: send the line unsubscribe linux-media in
the body of a message to majord...@vger.kernel.org
More majordomo info at