Re: [PATCH v7 09/14] media: v4l2-subdev: Always call get_fmt() if set_fmt() is unavailable

Hans Verkuil <[email protected]>
Newsgroups org.kernel.vger.linux-media
Message-ID <[email protected]>
On 07/08/2026 14:24, Sakari Ailus wrote:
> Many drivers implement set_fmt() pad op that simply returns the format
> just as get_fmt() would do, usually because the driver only supports a
> single one. As a driver should always implement set_fmt() either on its
> own or via get_fmt(), call get_fmt() in case set_fmt() isn't implemented
> by the driver. This allows removing a fair amount of boilerplate code as
> well as ensures that set_fmt() works whenever get_fmt() does.
> 
> Signed-off-by: Sakari Ailus <[email protected]>

Reviewed-by: Hans Verkuil <[email protected]>

Regards,

	Hans

> ---
>  drivers/media/v4l2-core/v4l2-subdev.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
> index f53bac995822..58e50d9442e7 100644
> --- a/drivers/media/v4l2-core/v4l2-subdev.c
> +++ b/drivers/media/v4l2-core/v4l2-subdev.c
> @@ -260,8 +260,19 @@ static int call_set_fmt(struct v4l2_subdev *sd,
>  			struct v4l2_subdev_state *state,
>  			struct v4l2_subdev_format *format)
>  {
> -	return do_subdev_call(sd, check_format(sd, state, format), pad, set_fmt,
> -			      state, format);
> +	int ret;
> +
> +	if (!sd->ops->pad->set_fmt && !sd->ops->pad->get_fmt)
> +		return -ENOIOCTLCMD;
> +
> +	ret = check_format(sd, state, format);
> +	if (ret)
> +		return ret;
> +
> +	if (sd->ops->pad->set_fmt)
> +		return sd->ops->pad->set_fmt(sd, state, format);
> +
> +	return sd->ops->pad->get_fmt(sd, state, format);
>  }
>  
>  static int check_which_pad_state(struct v4l2_subdev *sd,
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.