Message ID | 20231013104424.404768-1-sakari.ailus@linux.intel.com |
---|---|
Headers | show |
Series | Unify sub-device state access functions | expand |
Hi Sakari, Thank you for the patch. On Fri, Oct 13, 2023 at 01:44:22PM +0300, Sakari Ailus wrote: > Now that v4l2_subdev_get_format() always returns format, don't call > alternative v4l2_subdev_get_pad_format() anymore. > > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Assuming we go forward for 2/6, this patch looks fine. Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> > --- > drivers/media/v4l2-core/v4l2-subdev.c | 9 +-------- > 1 file changed, 1 insertion(+), 8 deletions(-) > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c > index a522cd8096cf..153e9b1958d6 100644 > --- a/drivers/media/v4l2-core/v4l2-subdev.c > +++ b/drivers/media/v4l2-core/v4l2-subdev.c > @@ -1580,14 +1580,7 @@ int v4l2_subdev_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_state *state, > { > struct v4l2_mbus_framefmt *fmt; > > - if (sd->flags & V4L2_SUBDEV_FL_STREAMS) > - fmt = v4l2_subdev_get_format(state, format->pad, > - format->stream); > - else if (format->pad < sd->entity.num_pads && format->stream == 0) > - fmt = v4l2_subdev_get_pad_format(sd, state, format->pad); > - else > - fmt = NULL; > - > + fmt = v4l2_subdev_get_format(state, format->pad, format->stream); > if (!fmt) > return -EINVAL; >
Hi Sakari, Thank you for the patch. On Fri, Oct 13, 2023 at 01:44:20PM +0300, Sakari Ailus wrote: > There are two sets of functions that return information from sub-device > state, one for stream-unaware users and another for stream-aware users. > Add support for stream-aware functions to return format, crop and compose > information from pad-based array that are functionally equivalent to the > old, stream-unaware ones. > > Also check state is non-NULL, in order to guard against old drivers > potentially calling this with NULL state for active formats or selection > rectangles. I'm not too keen on this I'm afraid :-( I think it gets confusing for drivers that are not stream-aware to have to call a function that takes a stream number. I don't see a problem with keeping two different sets of functions, one for stream-aware drivers, and one for other drivers. > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> > --- > drivers/media/v4l2-core/v4l2-subdev.c | 39 +++++++++++++++++++++++++++ > 1 file changed, 39 insertions(+) > > diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c > index 52a8043ab556..7d0ce8c8aab4 100644 > --- a/drivers/media/v4l2-core/v4l2-subdev.c > +++ b/drivers/media/v4l2-core/v4l2-subdev.c > @@ -1684,6 +1684,19 @@ v4l2_subdev_state_get_stream_format(struct v4l2_subdev_state *state, > struct v4l2_subdev_stream_configs *stream_configs; > unsigned int i; > > + if (WARN_ON(!state)) > + return NULL; > + > + if (state->pads) { > + if (stream) > + return NULL; > + > + if (WARN_ON(pad >= state->num_pads)) > + pad = 0; > + > + return &state->pads[pad].try_fmt; > + } > + > lockdep_assert_held(state->lock); > > stream_configs = &state->stream_configs; > @@ -1705,6 +1718,19 @@ v4l2_subdev_state_get_stream_crop(struct v4l2_subdev_state *state, > struct v4l2_subdev_stream_configs *stream_configs; > unsigned int i; > > + if (WARN_ON(!state)) > + return NULL; > + > + if (state->pads) { > + if (stream) > + return NULL; > + > + if (WARN_ON(pad >= state->num_pads)) > + pad = 0; > + > + return &state->pads[pad].try_crop; > + } > + > lockdep_assert_held(state->lock); > > stream_configs = &state->stream_configs; > @@ -1726,6 +1752,19 @@ v4l2_subdev_state_get_stream_compose(struct v4l2_subdev_state *state, > struct v4l2_subdev_stream_configs *stream_configs; > unsigned int i; > > + if (WARN_ON(!state)) > + return NULL; > + > + if (state->pads) { > + if (stream) > + return NULL; > + > + if (WARN_ON(pad >= state->num_pads)) > + pad = 0; > + > + return &state->pads[pad].try_compose; > + } > + > lockdep_assert_held(state->lock); > > stream_configs = &state->stream_configs;
On Fri, Oct 13, 2023 at 11:06:08AM +0000, Sakari Ailus wrote: > On Fri, Oct 13, 2023 at 01:57:49PM +0300, Laurent Pinchart wrote: > > On Fri, Oct 13, 2023 at 01:44:19PM +0300, Sakari Ailus wrote: > > > Store the number of pads in the sub-device state. This will be needed to > > > validate pad when retrieving information for non-stream-aware users. > > > > I'd rather store a pointer to the subdev. You can get the number of pads > > from there. > > The value is initialised after the array is allocated so this won't change. > > I don't have a strong opinion either way. It's still more efficient to > store just the value. Slightly so, but I don't think it will matter in practice. I believe we'll have more needs to access the subdev from the state in the future, which is why I'd rather store the pointer already.
Hi Sakari, On Fri, Oct 13, 2023 at 11:13:00AM +0000, Sakari Ailus wrote: > On Fri, Oct 13, 2023 at 02:07:41PM +0300, Laurent Pinchart wrote: > > On Fri, Oct 13, 2023 at 01:44:20PM +0300, Sakari Ailus wrote: > > > There are two sets of functions that return information from sub-device > > > state, one for stream-unaware users and another for stream-aware users. > > > Add support for stream-aware functions to return format, crop and compose > > > information from pad-based array that are functionally equivalent to the > > > old, stream-unaware ones. > > > > > > Also check state is non-NULL, in order to guard against old drivers > > > potentially calling this with NULL state for active formats or selection > > > rectangles. > > > > I'm not too keen on this I'm afraid :-( I think it gets confusing for > > drivers that are not stream-aware to have to call a function that takes > > a stream number. I don't see a problem with keeping two different sets > > of functions, one for stream-aware drivers, and one for other drivers. > > This becomes a nuisance in drivers such as CCS that work with sub-devices > some of which have streams and others which don't. I don't see why we > should have two sets of functions to access the same information, even > though it's stored differently. > > I can add a wrapper using C11 _Generic to make the stream number go away. That could possibly be interesting.
On Mon, Oct 16, 2023 at 11:24:52AM +0300, Laurent Pinchart wrote: > Hi Sakari, > > On Fri, Oct 13, 2023 at 11:13:00AM +0000, Sakari Ailus wrote: > > On Fri, Oct 13, 2023 at 02:07:41PM +0300, Laurent Pinchart wrote: > > > On Fri, Oct 13, 2023 at 01:44:20PM +0300, Sakari Ailus wrote: > > > > There are two sets of functions that return information from sub-device > > > > state, one for stream-unaware users and another for stream-aware users. > > > > Add support for stream-aware functions to return format, crop and compose > > > > information from pad-based array that are functionally equivalent to the > > > > old, stream-unaware ones. > > > > > > > > Also check state is non-NULL, in order to guard against old drivers > > > > potentially calling this with NULL state for active formats or selection > > > > rectangles. > > > > > > I'm not too keen on this I'm afraid :-( I think it gets confusing for > > > drivers that are not stream-aware to have to call a function that takes > > > a stream number. I don't see a problem with keeping two different sets > > > of functions, one for stream-aware drivers, and one for other drivers. > > > > This becomes a nuisance in drivers such as CCS that work with sub-devices > > some of which have streams and others which don't. I don't see why we > > should have two sets of functions to access the same information, even > > though it's stored differently. > > > > I can add a wrapper using C11 _Generic to make the stream number go away. > > That could possibly be interesting. I'll add this for v2.
On Mon, Oct 16, 2023 at 08:59:15AM +0000, Sakari Ailus wrote: > On Mon, Oct 16, 2023 at 11:24:52AM +0300, Laurent Pinchart wrote: > > Hi Sakari, > > > > On Fri, Oct 13, 2023 at 11:13:00AM +0000, Sakari Ailus wrote: > > > On Fri, Oct 13, 2023 at 02:07:41PM +0300, Laurent Pinchart wrote: > > > > On Fri, Oct 13, 2023 at 01:44:20PM +0300, Sakari Ailus wrote: > > > > > There are two sets of functions that return information from sub-device > > > > > state, one for stream-unaware users and another for stream-aware users. > > > > > Add support for stream-aware functions to return format, crop and compose > > > > > information from pad-based array that are functionally equivalent to the > > > > > old, stream-unaware ones. > > > > > > > > > > Also check state is non-NULL, in order to guard against old drivers > > > > > potentially calling this with NULL state for active formats or selection > > > > > rectangles. > > > > > > > > I'm not too keen on this I'm afraid :-( I think it gets confusing for > > > > drivers that are not stream-aware to have to call a function that takes > > > > a stream number. I don't see a problem with keeping two different sets > > > > of functions, one for stream-aware drivers, and one for other drivers. > > > > > > This becomes a nuisance in drivers such as CCS that work with sub-devices > > > some of which have streams and others which don't. I don't see why we > > > should have two sets of functions to access the same information, even > > > though it's stored differently. > > > > > > I can add a wrapper using C11 _Generic to make the stream number go away. > > > > That could possibly be interesting. > > I'll add this for v2. C11 _Generic() isn't up to the task as it only deals with argument types. On the other hand, variadic arguments supports this. It'll look like: #define v4l2_subdev_get_crop(state, pad, ...) \ __v4l2_subdev_get_crop_ ## __VA_OPT__(stream) \ (state, pad __VA_OPT__(,) __VA_ARGS__) #define __v4l2_subdev_get_crop_(state, pad) \ __v4l2_subdev_get_crop(state, pad, 0) #define __v4l2_subdev_get_crop_stream(state, pad, stream) \ __v4l2_subdev_get_crop(state, pad, stream) struct v4l2_rect * __v4l2_subdev_get_crop(struct v4l2_subdev_state *state, unsigned int pad, u32 stream); Which I'd say is tolerable, given the result is a single function to access format, crop and compose information in the sub-device state. Any thoughts on this?
On Mon, Oct 16, 2023 at 10:21:45AM +0000, Sakari Ailus wrote: > On Mon, Oct 16, 2023 at 08:59:15AM +0000, Sakari Ailus wrote: > > On Mon, Oct 16, 2023 at 11:24:52AM +0300, Laurent Pinchart wrote: > > > On Fri, Oct 13, 2023 at 11:13:00AM +0000, Sakari Ailus wrote: > > > > On Fri, Oct 13, 2023 at 02:07:41PM +0300, Laurent Pinchart wrote: > > > > > On Fri, Oct 13, 2023 at 01:44:20PM +0300, Sakari Ailus wrote: > > > > > > There are two sets of functions that return information from sub-device > > > > > > state, one for stream-unaware users and another for stream-aware users. > > > > > > Add support for stream-aware functions to return format, crop and compose > > > > > > information from pad-based array that are functionally equivalent to the > > > > > > old, stream-unaware ones. > > > > > > > > > > > > Also check state is non-NULL, in order to guard against old drivers > > > > > > potentially calling this with NULL state for active formats or selection > > > > > > rectangles. > > > > > > > > > > I'm not too keen on this I'm afraid :-( I think it gets confusing for > > > > > drivers that are not stream-aware to have to call a function that takes > > > > > a stream number. I don't see a problem with keeping two different sets > > > > > of functions, one for stream-aware drivers, and one for other drivers. > > > > > > > > This becomes a nuisance in drivers such as CCS that work with sub-devices > > > > some of which have streams and others which don't. I don't see why we > > > > should have two sets of functions to access the same information, even > > > > though it's stored differently. > > > > > > > > I can add a wrapper using C11 _Generic to make the stream number go away. > > > > > > That could possibly be interesting. > > > > I'll add this for v2. > > C11 _Generic() isn't up to the task as it only deals with argument types. On > the other hand, variadic arguments supports this. It'll look like: > > #define v4l2_subdev_get_crop(state, pad, ...) \ > __v4l2_subdev_get_crop_ ## __VA_OPT__(stream) \ > (state, pad __VA_OPT__(,) __VA_ARGS__) > #define __v4l2_subdev_get_crop_(state, pad) \ > __v4l2_subdev_get_crop(state, pad, 0) > #define __v4l2_subdev_get_crop_stream(state, pad, stream) \ > __v4l2_subdev_get_crop(state, pad, stream) > struct v4l2_rect * > __v4l2_subdev_get_crop(struct v4l2_subdev_state *state, unsigned int pad, > u32 stream); > > Which I'd say is tolerable, given the result is a single function to access > format, crop and compose information in the sub-device state. > > Any thoughts on this? With s/v4l2_subdev_get_crop/v4l2_subdev_state_get_crop/ I'm OK with this.