media: i2c: st-mipid02: correct format propagation

Message ID 20231113145731.89796-1-alain.volmat@foss.st.com
State New
Headers
Series media: i2c: st-mipid02: correct format propagation |

Commit Message

Alain Volmat Nov. 13, 2023, 2:57 p.m. UTC
  Use a copy of the struct v4l2_subdev_format when propagating
format from the sink to source pad in order to avoid impacting the
sink format returned to the application.

Thanks to Jacopo Mondi for pointing the issue.

Fixes: 6c01e6f3f27b ("media: st-mipid02: Propagate format from sink to source pad")
Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Cc: stable@vger.kernel.org
---
 drivers/media/i2c/st-mipid02.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
  

Comments

Jacopo Mondi Nov. 13, 2023, 4:15 p.m. UTC | #1
Hello Alain

On Mon, Nov 13, 2023 at 03:57:30PM +0100, Alain Volmat wrote:
> Use a copy of the struct v4l2_subdev_format when propagating
> format from the sink to source pad in order to avoid impacting the
> sink format returned to the application.
>
> Thanks to Jacopo Mondi for pointing the issue.
>

;)

> Fixes: 6c01e6f3f27b ("media: st-mipid02: Propagate format from sink to source pad")
> Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
> Cc: stable@vger.kernel.org
> ---
>  drivers/media/i2c/st-mipid02.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index fa27638edc07..dab14787116b 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -770,6 +770,7 @@ static void mipid02_set_fmt_sink(struct v4l2_subdev *sd,
>  				 struct v4l2_subdev_format *format)
>  {
>  	struct mipid02_dev *bridge = to_mipid02_dev(sd);
> +	struct v4l2_subdev_format source_fmt;
>  	struct v4l2_mbus_framefmt *fmt;
>
>  	format->format.code = get_fmt_code(format->format.code);
> @@ -781,8 +782,12 @@ static void mipid02_set_fmt_sink(struct v4l2_subdev *sd,
>
>  	*fmt = format->format;
>
> -	/* Propagate the format change to the source pad */
> -	mipid02_set_fmt_source(sd, sd_state, format);
> +	/*
> +	 * Propagate the format change to the source pad, taking
> +	 * care not to update the format pointer given back to user
> +	 */
> +	source_fmt = *format;
> +	mipid02_set_fmt_source(sd, sd_state, &source_fmt);

Looks good!
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Thanks
  j

>  }
>
>  static int mipid02_set_fmt(struct v4l2_subdev *sd,
> --
> 2.25.1
>
  
Benjamin Mugnier Nov. 14, 2023, 2:40 p.m. UTC | #2
Hello Alain,

Thanks a lot !

On 11/13/23 15:57, Alain Volmat wrote:
> Use a copy of the struct v4l2_subdev_format when propagating
> format from the sink to source pad in order to avoid impacting the
> sink format returned to the application.
> 
> Thanks to Jacopo Mondi for pointing the issue.

Reviewed-by: Benjamin Mugnier <benjamin.mugnier@foss.st.com>

> Fixes: 6c01e6f3f27b ("media: st-mipid02: Propagate format from sink to source pad")
> Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
> Cc: stable@vger.kernel.org
> ---
>  drivers/media/i2c/st-mipid02.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index fa27638edc07..dab14787116b 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -770,6 +770,7 @@ static void mipid02_set_fmt_sink(struct v4l2_subdev *sd,
>  				 struct v4l2_subdev_format *format)
>  {
>  	struct mipid02_dev *bridge = to_mipid02_dev(sd);
> +	struct v4l2_subdev_format source_fmt;
>  	struct v4l2_mbus_framefmt *fmt;
>  
>  	format->format.code = get_fmt_code(format->format.code);
> @@ -781,8 +782,12 @@ static void mipid02_set_fmt_sink(struct v4l2_subdev *sd,
>  
>  	*fmt = format->format;
>  
> -	/* Propagate the format change to the source pad */
> -	mipid02_set_fmt_source(sd, sd_state, format);
> +	/*
> +	 * Propagate the format change to the source pad, taking
> +	 * care not to update the format pointer given back to user
> +	 */
> +	source_fmt = *format;
> +	mipid02_set_fmt_source(sd, sd_state, &source_fmt);
>  }
>  
>  static int mipid02_set_fmt(struct v4l2_subdev *sd,
  
Dan Scally Nov. 14, 2023, 3:19 p.m. UTC | #3
Hi Alain

On 13/11/2023 14:57, Alain Volmat wrote:
> Use a copy of the struct v4l2_subdev_format when propagating
> format from the sink to source pad in order to avoid impacting the
> sink format returned to the application.
>
> Thanks to Jacopo Mondi for pointing the issue.
>
> Fixes: 6c01e6f3f27b ("media: st-mipid02: Propagate format from sink to source pad")
> Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
> Cc: stable@vger.kernel.org
> ---

Oops - sorry about that!


Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>

>   drivers/media/i2c/st-mipid02.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
> index fa27638edc07..dab14787116b 100644
> --- a/drivers/media/i2c/st-mipid02.c
> +++ b/drivers/media/i2c/st-mipid02.c
> @@ -770,6 +770,7 @@ static void mipid02_set_fmt_sink(struct v4l2_subdev *sd,
>   				 struct v4l2_subdev_format *format)
>   {
>   	struct mipid02_dev *bridge = to_mipid02_dev(sd);
> +	struct v4l2_subdev_format source_fmt;
>   	struct v4l2_mbus_framefmt *fmt;
>   
>   	format->format.code = get_fmt_code(format->format.code);
> @@ -781,8 +782,12 @@ static void mipid02_set_fmt_sink(struct v4l2_subdev *sd,
>   
>   	*fmt = format->format;
>   
> -	/* Propagate the format change to the source pad */
> -	mipid02_set_fmt_source(sd, sd_state, format);
> +	/*
> +	 * Propagate the format change to the source pad, taking
> +	 * care not to update the format pointer given back to user
> +	 */
> +	source_fmt = *format;
> +	mipid02_set_fmt_source(sd, sd_state, &source_fmt);
>   }
>   
>   static int mipid02_set_fmt(struct v4l2_subdev *sd,
  

Patch

diff --git a/drivers/media/i2c/st-mipid02.c b/drivers/media/i2c/st-mipid02.c
index fa27638edc07..dab14787116b 100644
--- a/drivers/media/i2c/st-mipid02.c
+++ b/drivers/media/i2c/st-mipid02.c
@@ -770,6 +770,7 @@  static void mipid02_set_fmt_sink(struct v4l2_subdev *sd,
 				 struct v4l2_subdev_format *format)
 {
 	struct mipid02_dev *bridge = to_mipid02_dev(sd);
+	struct v4l2_subdev_format source_fmt;
 	struct v4l2_mbus_framefmt *fmt;
 
 	format->format.code = get_fmt_code(format->format.code);
@@ -781,8 +782,12 @@  static void mipid02_set_fmt_sink(struct v4l2_subdev *sd,
 
 	*fmt = format->format;
 
-	/* Propagate the format change to the source pad */
-	mipid02_set_fmt_source(sd, sd_state, format);
+	/*
+	 * Propagate the format change to the source pad, taking
+	 * care not to update the format pointer given back to user
+	 */
+	source_fmt = *format;
+	mipid02_set_fmt_source(sd, sd_state, &source_fmt);
 }
 
 static int mipid02_set_fmt(struct v4l2_subdev *sd,