mbox series

[v4,0/3] media: v4l2-subdev: Support const-awareness in state accessors

Message ID 20240508214045.24716-1-laurent.pinchart+renesas@ideasonboard.com
Headers show
Series media: v4l2-subdev: Support const-awareness in state accessors | expand

Message

Laurent Pinchart May 8, 2024, 9:40 p.m. UTC
This small patch series comes from a mild annoyance I experienced during
a recent patch review, where I wanted to ask for a pointer to a
v4l2_subdev_state used to access the state in a read-only fashion to be
made const. This wasn't possible as the state accessors functions take a
non-const state pointer, in order to return pointers to mutable formats
and selection rectangles.

Patch 1/3 first fixes a small documentation mistake. Patch 2/3 improves
the state accessors to support const states, in the same wait as the
recently introduced container_of_const() macro. The internal macro name
has been subject to a bit of bikeshedding already, so I think we're
reaching a final version. Patch 3/3 then shows how this can be used in
one driver.

Compared to v3, patch 1/3 is new, and patch 2/3 renames the new macro
and updates documentation.

Laurent Pinchart (3):
  media: v4l2-subdev: Fix v4l2_subdev_state_get_format() documentation
  media: v4l2-subdev: Provide const-aware subdev state accessors
  media: rkisp1: Mark subdev state pointers as const

 .../platform/rockchip/rkisp1/rkisp1-isp.c     |  8 +--
 .../platform/rockchip/rkisp1/rkisp1-resizer.c |  8 +--
 include/media/v4l2-subdev.h                   | 50 +++++++++++++------
 3 files changed, 42 insertions(+), 24 deletions(-)


base-commit: e695668af8523b059127dfa8b261c76e7c9cde10

Comments

Sakari Ailus May 9, 2024, 6:29 p.m. UTC | #1
Hi Laurent,

Thanks for posting this.

On Thu, May 09, 2024 at 12:40:43AM +0300, Laurent Pinchart wrote:
> The documentation of the v4l2_subdev_state_get_format() macro
> incorrectly references __v4l2_subdev_state_get_format() instead of
> __v4l2_subdev_state_gen_call(). Fix it, and also update the list of
> similar macros to add the missing v4l2_subdev_state_get_interval().
> 
> Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> ---
>  include/media/v4l2-subdev.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> index e30c463d90e5..b25b6e97ecbd 100644
> --- a/include/media/v4l2-subdev.h
> +++ b/include/media/v4l2-subdev.h
> @@ -1340,12 +1340,12 @@ void v4l2_subdev_cleanup(struct v4l2_subdev *sd);
>   */
>  /*
>   * Wrap v4l2_subdev_state_get_format(), allowing the function to be called with
> - * two or three arguments. The purpose of the __v4l2_subdev_state_get_format()
> + * two or three arguments. The purpose of the __v4l2_subdev_state_gen_call()
>   * macro below is to come up with the name of the function or macro to call,

You could drop "below" here, too: the macro definition is above the text.

Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>

>   * using the last two arguments (_stream and _pad). The selected function or
>   * macro is then called using the arguments specified by the caller. A similar
> - * arrangement is used for v4l2_subdev_state_crop() and
> - * v4l2_subdev_state_compose() below.
> + * arrangement is used for v4l2_subdev_state_crop(), v4l2_subdev_state_compose()
> + * and v4l2_subdev_state_get_interval() below.
>   */
>  #define v4l2_subdev_state_get_format(state, pad, ...)			\
>  	__v4l2_subdev_state_gen_call(format, ##__VA_ARGS__, , _pad)	\
Laurent Pinchart May 9, 2024, 8:04 p.m. UTC | #2
On Thu, May 09, 2024 at 06:29:41PM +0000, Sakari Ailus wrote:
> On Thu, May 09, 2024 at 12:40:43AM +0300, Laurent Pinchart wrote:
> > The documentation of the v4l2_subdev_state_get_format() macro
> > incorrectly references __v4l2_subdev_state_get_format() instead of
> > __v4l2_subdev_state_gen_call(). Fix it, and also update the list of
> > similar macros to add the missing v4l2_subdev_state_get_interval().
> > 
> > Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> > ---
> >  include/media/v4l2-subdev.h | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h
> > index e30c463d90e5..b25b6e97ecbd 100644
> > --- a/include/media/v4l2-subdev.h
> > +++ b/include/media/v4l2-subdev.h
> > @@ -1340,12 +1340,12 @@ void v4l2_subdev_cleanup(struct v4l2_subdev *sd);
> >   */
> >  /*
> >   * Wrap v4l2_subdev_state_get_format(), allowing the function to be called with
> > - * two or three arguments. The purpose of the __v4l2_subdev_state_get_format()
> > + * two or three arguments. The purpose of the __v4l2_subdev_state_gen_call()
> >   * macro below is to come up with the name of the function or macro to call,
> 
> You could drop "below" here, too: the macro definition is above the text.

I think "below" here refers to "usage below". I'll drop it nonetheless.

> Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>

Thanks.

> >   * using the last two arguments (_stream and _pad). The selected function or
> >   * macro is then called using the arguments specified by the caller. A similar
> > - * arrangement is used for v4l2_subdev_state_crop() and
> > - * v4l2_subdev_state_compose() below.
> > + * arrangement is used for v4l2_subdev_state_crop(), v4l2_subdev_state_compose()
> > + * and v4l2_subdev_state_get_interval() below.
> >   */
> >  #define v4l2_subdev_state_get_format(state, pad, ...)			\
> >  	__v4l2_subdev_state_gen_call(format, ##__VA_ARGS__, , _pad)	\