Old non-MC-aware drivers have no sub-device state
Subsystems (6)
Sakari Ailus
maintainercover Old non-MC-aware drivers have no sub-device state
Hi folks,
This set replaces the earlier attempt to fix non-MC-aware sub-device drivers that still use the set_fmt and similar sub-device ops. These drivers have been converted from the olf set_fmt etc. video ops.
The issue here is that the caller does not initialise the full sub-device state so the sd field of struct v4l2_subdev_state is NULL, leading currently to NULL pointer dereference, even if the code compiles. This was not the case before commit fd17e3a9a7886ec949ce269a396b67875b51ff45 .
Even then, there's no need to access the sub-device state as the format (or selection rectangle) won't be stored for a longer period of time: the caller (saa7134 driver) simply uses the original configuration to obtain the changed value.
This patchset does not address similar issues in the ov6650 driver.
Sakari Ailus (6):
media: saa6752hs: Don't set format in sub-device state
media: adv7183: Don't set format in sub-device state
media: mt9t112: Don't set format in sub-device state
media: rj54n1cb0c: Don't set format in sub-device state
media: tw9910: Don't set format in sub-device state
media: ov9640: Don't set format in sub-device state
drivers/media/i2c/adv7183.c | 2 -- drivers/media/i2c/mt9t112.c | 1 - drivers/media/i2c/ov9640.c | 2 -- drivers/media/i2c/rj54n1cb0c.c | 4 +--- drivers/media/i2c/saa6752hs.c | 4 +--- drivers/media/i2c/tw9910.c | 2 -- 6 files changed, 2 insertions(+), 13 deletions(-)
Signature · 1 line
2.39.2
Sakari Ailus
maintainerPATCH 1/6 media: saa6752hs: Don't set format in sub-device state
For the purpose of setting old non-pad based sub-device try format as a basis for VIDIOC_TRY_FMT implementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.
--- drivers/media/i2c/saa6752hs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/media/i2c/saa6752hs.c +1 -3
@@ -594,10 +594,8 @@ static int saa6752hs_set_fmt(struct v4l2_subdev *sd, f->field =V4L2_FIELD_INTERLACED ; f->colorspace =V4L2_COLORSPACE_SMPTE170M ; -if (format->which ==V4L2_SUBDEV_FORMAT_TRY ) { - *v4l2_subdev_state_get_format (sd_state,0 ) = *f; +if (format->which ==V4L2_SUBDEV_FORMAT_TRY )return 0 ; - }/* FIXME: translate and round width/height into EMPRESS
Signature · 1 line
2.39.2
Re: [PATCH 1/6] media: saa6752hs: Don't set format in sub-device state
Hi Sakari,
Thank you for the patch.
Quoted 7 lines · Sakari Ailus
For the purpose of setting old non-pad based sub-device try format as a basis for
VIDIOC_TRY_FMTimplementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.Fixes fd17e3a9a788 ("media: i2c: Use accessors for pad config 'try_*' fields")Signed-off-by Sakari Ailus <[email protected]>
Quoted 20 lines
--- drivers/media/i2c/saa6752hs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/media/i2c/saa6752hs.c +1
-3@@ -594,10 +594,8 @@ static int saa6752hs_set_fmt(struct v4l2_subdev *sd, f->field =V4L2_FIELD_INTERLACED ; f->colorspace =V4L2_COLORSPACE_SMPTE170M ; -if (format->which ==V4L2_SUBDEV_FORMAT_TRY ) { - *v4l2_subdev_state_get_format (sd_state,0 ) = *f; +if (format->which ==V4L2_SUBDEV_FORMAT_TRY )return 0 ; - }/* FIXME: translate and round width/height into EMPRESS
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerPATCH 2/6 media: adv7183: Don't set format in sub-device state
In reply to Sakari AilusFor the purpose of setting old non-pad based sub-device try format as a basis for VIDIOC_TRY_FMT implementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.
--- drivers/media/i2c/adv7183.c | 2 -- 1 file changed, 2 deletions(-)
drivers/media/i2c/adv7183.c +0 -2
@@ -442,8 +442,6 @@ static int adv7183_set_fmt(struct v4l2_subdev *sd, }if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) decoder->fmt = *fmt; -else - *v4l2_subdev_state_get_format (sd_state,0 ) = *fmt;return 0 ; }
Signature · 1 line
2.39.2
Re: [PATCH 2/6] media: adv7183: Don't set format in sub-device state
Hi Sakari,
Thank you for the patch.
Quoted 7 lines · Sakari Ailus
For the purpose of setting old non-pad based sub-device try format as a basis for
VIDIOC_TRY_FMTimplementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.Fixes fd17e3a9a788 ("media: i2c: Use accessors for pad config 'try_*' fields")Signed-off-by Sakari Ailus <[email protected]>
Quoted 17 lines
--- drivers/media/i2c/adv7183.c | 2 -- 1 file changed, 2 deletions(-)drivers/media/i2c/adv7183.c +0
-2@@ -442,8 +442,6 @@ static int adv7183_set_fmt(struct v4l2_subdev *sd, }if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE ) decoder->fmt = *fmt; -else - *v4l2_subdev_state_get_format (sd_state,0 ) = *fmt;return 0 ; }
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerPATCH 3/6 media: mt9t112: Don't set format in sub-device state
In reply to Sakari AilusFor the purpose of setting old non-pad based sub-device try format as a basis for VIDIOC_TRY_FMT implementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.
--- drivers/media/i2c/mt9t112.c | 1 - 1 file changed, 1 deletion(-)
drivers/media/i2c/mt9t112.c +0 -1
@@ -982,7 +982,6 @@ static int mt9t112_set_fmt(struct v4l2_subdev *sd,if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE )return mt9t112_s_fmt (sd, mf); - *v4l2_subdev_state_get_format (sd_state,0 ) = *mf;return 0 ; }
Signature · 1 line
2.39.2
Re: [PATCH 3/6] media: mt9t112: Don't set format in sub-device state
Hi Sakari,
Thank you for the patch.
Quoted 7 lines · Sakari Ailus
For the purpose of setting old non-pad based sub-device try format as a basis for
VIDIOC_TRY_FMTimplementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.Fixes fd17e3a9a788 ("media: i2c: Use accessors for pad config 'try_*' fields")Signed-off-by Sakari Ailus <[email protected]>
Quoted 16 lines
--- drivers/media/i2c/mt9t112.c | 1 - 1 file changed, 1 deletion(-)drivers/media/i2c/mt9t112.c +0
-1@@ -982,7 +982,6 @@ static int mt9t112_set_fmt(struct v4l2_subdev *sd,if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE )return mt9t112_s_fmt (sd, mf); - *v4l2_subdev_state_get_format (sd_state,0 ) = *mf;return 0 ; }
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerPATCH 4/6 media: rj54n1cb0c: Don't set format in sub-device state
In reply to Sakari AilusFor the purpose of setting old non-pad based sub-device try format as a basis for VIDIOC_TRY_FMT implementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.
--- drivers/media/i2c/rj54n1cb0c.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/media/i2c/rj54n1cb0c.c +1 -3
@@ -1008,10 +1008,8 @@ static int rj54n1_set_fmt(struct v4l2_subdev *sd,v4l_bound_align_image (&mf->width,112 ,RJ54N1_MAX_WIDTH , align, &mf->height,84 ,RJ54N1_MAX_HEIGHT , align,0 ); -if (format->which ==V4L2_SUBDEV_FORMAT_TRY ) { - *v4l2_subdev_state_get_format (sd_state,0 ) = *mf; +if (format->which ==V4L2_SUBDEV_FORMAT_TRY )return 0 ; - }/* * Verify if the sensor has just been powered on. TODO: replace this
Signature · 1 line
2.39.2
Re: [PATCH 4/6] media: rj54n1cb0c: Don't set format in sub-device state
Hi Sakari,
Thank you for the patch.
Quoted 7 lines · Sakari Ailus
For the purpose of setting old non-pad based sub-device try format as a basis for
VIDIOC_TRY_FMTimplementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.Fixes fd17e3a9a788 ("media: i2c: Use accessors for pad config 'try_*' fields")Signed-off-by Sakari Ailus <[email protected]>
Quoted 20 lines
--- drivers/media/i2c/rj54n1cb0c.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/media/i2c/rj54n1cb0c.c +1
-3@@ -1008,10 +1008,8 @@ static int rj54n1_set_fmt(struct v4l2_subdev *sd,v4l_bound_align_image (&mf->width,112 ,RJ54N1_MAX_WIDTH , align, &mf->height,84 ,RJ54N1_MAX_HEIGHT , align,0 ); -if (format->which ==V4L2_SUBDEV_FORMAT_TRY ) { - *v4l2_subdev_state_get_format (sd_state,0 ) = *mf; +if (format->which ==V4L2_SUBDEV_FORMAT_TRY )return 0 ; - }/* * Verify if the sensor has just been powered on. TODO: replace this
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerPATCH 5/6 media: tw9910: Don't set format in sub-device state
In reply to Sakari AilusFor the purpose of setting old non-pad based sub-device try format as a basis for VIDIOC_TRY_FMT implementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.
--- drivers/media/i2c/tw9910.c | 2 -- 1 file changed, 2 deletions(-)
drivers/media/i2c/tw9910.c +0 -2
@@ -829,8 +829,6 @@ static int tw9910_set_fmt(struct v4l2_subdev *sd,if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE )return tw9910_s_fmt (sd, mf); - *v4l2_subdev_state_get_format (sd_state,0 ) = *mf; -return 0 ; }
Signature · 1 line
2.39.2
Re: [PATCH 5/6] media: tw9910: Don't set format in sub-device state
Hi Sakari,
Thank you for the patch.
Quoted 7 lines · Sakari Ailus
For the purpose of setting old non-pad based sub-device try format as a basis for
VIDIOC_TRY_FMTimplementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.Fixes fd17e3a9a788 ("media: i2c: Use accessors for pad config 'try_*' fields")Signed-off-by Sakari Ailus <[email protected]>
Quoted 17 lines
--- drivers/media/i2c/tw9910.c | 2 -- 1 file changed, 2 deletions(-)drivers/media/i2c/tw9910.c +0
-2@@ -829,8 +829,6 @@ static int tw9910_set_fmt(struct v4l2_subdev *sd,if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE )return tw9910_s_fmt (sd, mf); - *v4l2_subdev_state_get_format (sd_state,0 ) = *mf; -return 0 ; }
Signature · 3 lines
Regards, Laurent Pinchart
Sakari Ailus
maintainerPATCH 6/6 media: ov9640: Don't set format in sub-device state
In reply to Sakari AilusFor the purpose of setting old non-pad based sub-device try format as a basis for VIDIOC_TRY_FMT implementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.
--- drivers/media/i2c/ov9640.c | 2 -- 1 file changed, 2 deletions(-)
drivers/media/i2c/ov9640.c +0 -2
@@ -547,8 +547,6 @@ static int ov9640_set_fmt(struct v4l2_subdev *sd,if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE )return ov9640_s_fmt (sd, mf); - *v4l2_subdev_state_get_format (sd_state,0 ) = *mf; -return 0 ; }
Signature · 1 line
2.39.2
Re: [PATCH 6/6] media: ov9640: Don't set format in sub-device state
Hi Sakari,
Thank you for the patch.
Quoted 7 lines · Sakari Ailus
For the purpose of setting old non-pad based sub-device try format as a basis for
VIDIOC_TRY_FMTimplementation, there is no need to set the format in the sub-device state. Drop the assignment to the state, which would result in a NULL pointer dereference.Fixes fd17e3a9a788 ("media: i2c: Use accessors for pad config 'try_*' fields")Signed-off-by Sakari Ailus <[email protected]>
Quoted 17 lines
--- drivers/media/i2c/ov9640.c | 2 -- 1 file changed, 2 deletions(-)drivers/media/i2c/ov9640.c +0
-2@@ -547,8 +547,6 @@ static int ov9640_set_fmt(struct v4l2_subdev *sd,if (format->which ==V4L2_SUBDEV_FORMAT_ACTIVE )return ov9640_s_fmt (sd, mf); - *v4l2_subdev_state_get_format (sd_state,0 ) = *mf; -return 0 ; }
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 11 lines · Sakari Ailus
Hi folks,
This set replaces the earlier attempt to fix non-MC-aware sub-device drivers that still use the
set_fmtand similar sub-device ops. These drivers have been converted from the olfset_fmtetc. video ops.The issue here is that the caller does not initialise the full sub-device state so the sd field of struct
v4l2_subdev_stateis NULL, leading currently to NULL pointer dereference, even if the code compiles. This was not the case before commitfd17e3a9a7886ec949ce269a396b67875b51ff45.
Quoted 4 lines
Even then, there's no need to access the sub-device state as the format (or selection rectangle) won't be stored for a longer period of time: the caller (saa7134 driver) simply uses the original configuration to obtain the changed value.
Just a note that he caller for the other subdev drivers, renesas-ceu, does exactly the same thing, so the same fix is applicable.
Quoted 1 line
This patchset does not address similar issues in the ov6650 driver.
The driver is not used in mainline anymore. It was merged for an old OMAP1 device that has been dropped from the kernel.
I wonder if we should start moving some sensor drivers to staging...
Quoted 15 lines
Sakari Ailus (6):
media: saa6752hs: Don't set format in sub-device state
media: adv7183: Don't set format in sub-device state
media: mt9t112: Don't set format in sub-device state
media: rj54n1cb0c: Don't set format in sub-device state
media: tw9910: Don't set format in sub-device state
media: ov9640: Don't set format in sub-device statedrivers/media/i2c/adv7183.c | 2 -- drivers/media/i2c/mt9t112.c | 1 - drivers/media/i2c/ov9640.c | 2 -- drivers/media/i2c/rj54n1cb0c.c | 4 +--- drivers/media/i2c/saa6752hs.c | 4 +--- drivers/media/i2c/tw9910.c | 2 -- 6 files changed, 2 insertions(+), 13 deletions(-)
Signature · 3 lines
Regards, Laurent Pinchart