Message ID | 20220216130049.508664-7-tomi.valkeinen@ideasonboard.com |
---|---|
State | New |
Headers | show |
Series | v4l: subdev active state | expand |
On 2/16/22 14:00, Tomi Valkeinen wrote: > Add v4l2_subdev_call_state_active() macro to help calling subdev ops > that take a subdev state as a parameter. > > Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Regards, Hans > --- > include/media/v4l2-subdev.h | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h > index 84c02488d53f..0db61203c8d9 100644 > --- a/include/media/v4l2-subdev.h > +++ b/include/media/v4l2-subdev.h > @@ -1359,6 +1359,37 @@ extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers; > __result; \ > }) > > +/** > + * v4l2_subdev_call_state_active - call an operation of a v4l2_subdev which > + * takes state as a parameter, passing the > + * subdev its active state. > + * > + * @sd: pointer to the &struct v4l2_subdev > + * @o: name of the element at &struct v4l2_subdev_ops that contains @f. > + * Each element there groups a set of callbacks functions. > + * @f: callback function to be called. > + * The callback functions are defined in groups, according to > + * each element at &struct v4l2_subdev_ops. > + * @args: arguments for @f. > + * > + * This is similar to v4l2_subdev_call(), except that this version can only be > + * used for ops that take a subdev state as a parameter. The macro will get the > + * active state and lock it before calling the op, and unlock it after the > + * call. > + */ > +#define v4l2_subdev_call_state_active(sd, o, f, args...) \ > + ({ \ > + int __result; \ > + struct v4l2_subdev_state *state; \ > + state = v4l2_subdev_get_active_state(sd); \ > + if (state) \ > + v4l2_subdev_lock_state(state); \ > + __result = v4l2_subdev_call(sd, o, f, state, ##args); \ > + if (state) \ > + v4l2_subdev_unlock_state(state); \ > + __result; \ > + }) > + > /** > * v4l2_subdev_has_op - Checks if a subdev defines a certain operation. > *
On 2/28/22 09:59, Hans Verkuil wrote: > > > On 2/16/22 14:00, Tomi Valkeinen wrote: >> Add v4l2_subdev_call_state_active() macro to help calling subdev ops >> that take a subdev state as a parameter. >> >> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> > > Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Hmm, after reading Laurent's comments I also think I was a bit too hasty. It should either be moved to a v4l2-subdev-legacy.h header (are there other legacy functions that could be moved there as well?) or it should have 'legacy' or something like that in the name. Regards, Hans > > Regards, > > Hans > >> --- >> include/media/v4l2-subdev.h | 31 +++++++++++++++++++++++++++++++ >> 1 file changed, 31 insertions(+) >> >> diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h >> index 84c02488d53f..0db61203c8d9 100644 >> --- a/include/media/v4l2-subdev.h >> +++ b/include/media/v4l2-subdev.h >> @@ -1359,6 +1359,37 @@ extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers; >> __result; \ >> }) >> >> +/** >> + * v4l2_subdev_call_state_active - call an operation of a v4l2_subdev which >> + * takes state as a parameter, passing the >> + * subdev its active state. >> + * >> + * @sd: pointer to the &struct v4l2_subdev >> + * @o: name of the element at &struct v4l2_subdev_ops that contains @f. >> + * Each element there groups a set of callbacks functions. >> + * @f: callback function to be called. >> + * The callback functions are defined in groups, according to >> + * each element at &struct v4l2_subdev_ops. >> + * @args: arguments for @f. >> + * >> + * This is similar to v4l2_subdev_call(), except that this version can only be >> + * used for ops that take a subdev state as a parameter. The macro will get the >> + * active state and lock it before calling the op, and unlock it after the >> + * call. >> + */ >> +#define v4l2_subdev_call_state_active(sd, o, f, args...) \ >> + ({ \ >> + int __result; \ >> + struct v4l2_subdev_state *state; \ >> + state = v4l2_subdev_get_active_state(sd); \ >> + if (state) \ >> + v4l2_subdev_lock_state(state); \ >> + __result = v4l2_subdev_call(sd, o, f, state, ##args); \ >> + if (state) \ >> + v4l2_subdev_unlock_state(state); \ >> + __result; \ >> + }) >> + >> /** >> * v4l2_subdev_has_op - Checks if a subdev defines a certain operation. >> *
diff --git a/include/media/v4l2-subdev.h b/include/media/v4l2-subdev.h index 84c02488d53f..0db61203c8d9 100644 --- a/include/media/v4l2-subdev.h +++ b/include/media/v4l2-subdev.h @@ -1359,6 +1359,37 @@ extern const struct v4l2_subdev_ops v4l2_subdev_call_wrappers; __result; \ }) +/** + * v4l2_subdev_call_state_active - call an operation of a v4l2_subdev which + * takes state as a parameter, passing the + * subdev its active state. + * + * @sd: pointer to the &struct v4l2_subdev + * @o: name of the element at &struct v4l2_subdev_ops that contains @f. + * Each element there groups a set of callbacks functions. + * @f: callback function to be called. + * The callback functions are defined in groups, according to + * each element at &struct v4l2_subdev_ops. + * @args: arguments for @f. + * + * This is similar to v4l2_subdev_call(), except that this version can only be + * used for ops that take a subdev state as a parameter. The macro will get the + * active state and lock it before calling the op, and unlock it after the + * call. + */ +#define v4l2_subdev_call_state_active(sd, o, f, args...) \ + ({ \ + int __result; \ + struct v4l2_subdev_state *state; \ + state = v4l2_subdev_get_active_state(sd); \ + if (state) \ + v4l2_subdev_lock_state(state); \ + __result = v4l2_subdev_call(sd, o, f, state, ##args); \ + if (state) \ + v4l2_subdev_unlock_state(state); \ + __result; \ + }) + /** * v4l2_subdev_has_op - Checks if a subdev defines a certain operation. *
Add v4l2_subdev_call_state_active() macro to help calling subdev ops that take a subdev state as a parameter. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> --- include/media/v4l2-subdev.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)