On 24/03/2022 09:00, Tomi Valkeinen wrote: > Add v4l2_subdev_get_fmt() helper function which implements > v4l2_subdev_pad_ops.get_fmt using active state. Subdev drivers that > support active state and do not need to do anything special in their > get_fmt op can use this helper directly for v4l2_subdev_pad_ops.get_fmt. > > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@xxxxxxxxxxxxxxxx> > --- > drivers/media/v4l2-core/v4l2-subdev.c | 18 ++++++++++++++++++ > include/media/v4l2-subdev.h | 17 +++++++++++++++++ > 2 files changed, 35 insertions(+) > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c > index d8d1c9ef4dc4..cbc5ebff0656 100644 > --- a/drivers/media/v4l2-core/v4l2-subdev.c > +++ b/drivers/media/v4l2-core/v4l2-subdev.c > @@ -1029,6 +1029,24 @@ void v4l2_subdev_cleanup(struct v4l2_subdev *sd) > } > EXPORT_SYMBOL_GPL(v4l2_subdev_cleanup); > > +int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, > + struct v4l2_subdev_format *format) > +{ > + struct v4l2_mbus_framefmt *fmt; > + > + if (format->pad >= sd->entity.num_pads) > + return -EINVAL; > + > + fmt = v4l2_subdev_get_try_format(sd, state, format->pad); Let's use the new v4l2_subdev_get_pad_format helper here. > + if (!fmt) > + return -EINVAL; > + > + format->format = *fmt; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(v4l2_subdev_get_fmt); > + > #endif /* CONFIG_MEDIA_CONTROLLER */ > > void v4l2_subdev_init(struct v4l2_subdev *sd, const struct v4l2_subdev_ops *ops) > diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h > index 700ce376b22c..491bdbb1670c 100644 > --- a/include/media/v4l2-subdev.h > +++ b/include/media/v4l2-subdev.h > @@ -1300,6 +1300,23 @@ v4l2_subdev_lock_and_get_active_state(struct v4l2_subdev *sd) > return sd->active_state; > } > > +/** > + * v4l2_subdev_get_fmt() - Fill format based on state > + * @sd: subdevice > + * @state: subdevice state > + * @format: pointer to &struct v4l2_subdev_format > + * > + * Fill @format->format field based on the information in the @format struct. > + * > + * This function can be used by the subdev drivers which support active state to > + * implement v4l2_subdev_pad_ops.get_fmt if the subdev driver does not need to > + * do anything special in their get_fmt op. > + * > + * Returns 0 on success, error value otherwise. > + */ > +int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, > + struct v4l2_subdev_format *format); My main concern here is the function name: perhaps a prefix like v4l2_subdev_pad_op_get_fmt (or perhaps just _op_ without 'pad') makes it easier to see that this is a pad op helper. In any case, this is not a blocker. With the v4l2_subdev_get_pad_format above and an optional function rename you can add my: Reviewed-by: Hans Verkuil <hverkuil-cisco@xxxxxxxxx> Regards, Hans > + > #endif /* CONFIG_MEDIA_CONTROLLER */ > > /**