On Tue Jun 9 21:59:34 2026 +0300, 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]>
> Reviewed-by: Laurent Pinchart <[email protected]>

Patch committed.

Thanks,
Sakari Ailus

 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,
_______________________________________________
linuxtv-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to