Unlocked v4l2_ctrl_grab
cover Unlocked v4l2_ctrl_grab
Hi folks,
This set adds an unlocked variant of v4l2_ctrl_grab(). This is needed when there's a need not to release the control lock for grabbing a control.
Used by the imx319 driver, but beneficial on a bunch of other sensor drivers, too --- to grab the *flip controls.
Sakari Ailus (2):
v4l: ctrl: Remove old documentation from v4l2_ctrl_grab
v4l: ctrl: Provide unlocked variant of v4l2_ctrl_grab
drivers/media/v4l2-core/v4l2-ctrls.c | 14 ++++---------- include/media/v4l2-ctrls.h | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 11 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/2 v4l: ctrl: Remove old documentation from v4l2_ctrl_grab
v4l2_ctrl_grab() is documented in the header; there's no need to have a comment explaining what the function does in the .c file.
--- drivers/media/v4l2-core/v4l2-ctrls.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls.c +0 -6
@@ -2511,12 +2511,6 @@ void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active) }EXPORT_SYMBOL (v4l2_ctrl_activate); -/* Grab/ungrab a control. -Typically used when streaming starts and you want to grab controls, -preventing the user from changing them. - -Just call this and the framework will block any attempts to change -these controls. */ void v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed) {bool old;
Signature · 1 line
2.11.0
Re: [PATCH 1/2] v4l: ctrl: Remove old documentation from v4l2_ctrl_grab
Quoted 4 lines · Sakari Ailus
v4l2_ctrl_grab()is documented in the header; there's no need to have a comment explaining what the function does in the .c file.Signed-off-by Sakari Ailus <[email protected]>
Regards,
Hans
Quoted 22 lines
--- drivers/media/v4l2-core/v4l2-ctrls.c | 6 ------ 1 file changed, 6 deletions(-)drivers/media/v4l2-core/v4l2-ctrls.c +0
-6@@ -2511,12 +2511,6 @@ void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active) }EXPORT_SYMBOL (v4l2_ctrl_activate); -/* Grab/ungrab a control. -Typically used when streaming starts and you want to grab controls, -preventing the user from changing them. - -Just call this and the framework will block any attempts to change -these controls. */ void v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed) {bool old;
PATCH 2/2 v4l: ctrl: Provide unlocked variant of v4l2_ctrl_grab
In reply to Sakari AilusSometimes it may be necessary to grab a control while holding the control handler's lock. Provide an unlocked variant of v4l2_ctrl_grab for the purpose --- it's called __v4l2_ctrl_grab.
--- drivers/media/v4l2-core/v4l2-ctrls.c | 8 ++++---- include/media/v4l2-ctrls.h | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls.c +4 -4
@@ -2511,14 +2511,15 @@ void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active) }EXPORT_SYMBOL (v4l2_ctrl_activate); -void v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed) +void __v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed) {bool old;if (ctrl ==NULL )return ; -v4l2_ctrl_lock (ctrl); +lockdep_assert_held (ctrl->handler->lock); +if (grabbed)/* set V4L2_CTRL_FLAG_GRABBED */ old =test_and_set_bit (1 , &ctrl->flags);
@@ -2527,9 +2528,8 @@ void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed) old =test_and_clear_bit (1 , &ctrl->flags);if (old != grabbed)send_event (NULL , ctrl,V4L2_EVENT_CTRL_CH_FLAGS ); -v4l2_ctrl_unlock (ctrl); } -EXPORT_SYMBOL (v4l2_ctrl_grab); +EXPORT_SYMBOL (__v4l2_ctrl_grab);/* Log the control name and value */ static void log_ctrl(const struct v4l2_ctrl *ctrl,
include/media/v4l2-ctrls.h +25 -1
@@ -729,6 +729,22 @@ struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);void v4l2_ctrl_activate (struct v4l2_ctrl *ctrl,bool active);/** +* __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab. +* +* @ctrl: The control to (de)activate. +* @grabbed: True if the control should become grabbed. +* +* This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically. +* Does nothing if @ctrl == NULL. +* The V4L2_EVENT_CTRL event will be generated afterwards. +* This will usually be called when starting or stopping streaming in the +* driver. +* +* This function assumes that the control handler is locked by the caller. +*/ +void __v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed); + +/** * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed. * * @ctrl: The control to (de)activate.
@@ -743,7 +759,15 @@ void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);* This function assumes that the control handler is not locked and will * take the lock itself. */ -void v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed); +static inline void v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed) +{ +if (!ctrl) +return ; + +v4l2_ctrl_lock (ctrl); +__v4l2_ctrl_grab (ctrl, grabbed); +v4l2_ctrl_unlock (ctrl); +}/** *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()
Signature · 1 line
2.11.0
Re: [PATCH 2/2] v4l: ctrl: Provide unlocked variant of v4l2_ctrl_grab
Quoted 5 lines · Sakari Ailus
Sometimes it may be necessary to grab a control while holding the control handler's lock. Provide an unlocked variant of
v4l2_ctrl_grabfor the purpose --- it's called__v4l2_ctrl_grab.Signed-off-by Sakari Ailus <[email protected]>
Regards,
Hans
Quoted 83 lines
--- drivers/media/v4l2-core/v4l2-ctrls.c | 8 ++++---- include/media/v4l2-ctrls.h | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-)drivers/media/v4l2-core/v4l2-ctrls.c +4
-4@@ -2511,14 +2511,15 @@ void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active) }EXPORT_SYMBOL (v4l2_ctrl_activate); -void v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed) +void __v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed) {bool old;if (ctrl ==NULL )return ; -v4l2_ctrl_lock (ctrl); +lockdep_assert_held (ctrl->handler->lock); +if (grabbed)/* set V4L2_CTRL_FLAG_GRABBED */ old =test_and_set_bit (1 , &ctrl->flags);@@ -2527,9 +2528,8 @@ void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed) old =test_and_clear_bit (1 , &ctrl->flags);if (old != grabbed)send_event (NULL , ctrl,V4L2_EVENT_CTRL_CH_FLAGS ); -v4l2_ctrl_unlock (ctrl); } -EXPORT_SYMBOL (v4l2_ctrl_grab); +EXPORT_SYMBOL (__v4l2_ctrl_grab);/* Log the control name and value */ static void log_ctrl(const struct v4l2_ctrl *ctrl,include/media/v4l2-ctrls.h +25
-1@@ -729,6 +729,22 @@ struct v4l2_ctrl *v4l2_ctrl_find(struct v4l2_ctrl_handler *hdl, u32 id);void v4l2_ctrl_activate (struct v4l2_ctrl *ctrl,bool active);/** +* __v4l2_ctrl_grab() - Unlocked variant of v4l2_ctrl_grab. +* +* @ctrl: The control to (de)activate. +* @grabbed: True if the control should become grabbed. +* +* This sets or clears the V4L2_CTRL_FLAG_GRABBED flag atomically. +* Does nothing if @ctrl == NULL. +* The V4L2_EVENT_CTRL event will be generated afterwards. +* This will usually be called when starting or stopping streaming in the +* driver. +* +* This function assumes that the control handler is locked by the caller. +*/ +void __v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed); + +/** * v4l2_ctrl_grab() - Mark the control as grabbed or not grabbed. * * @ctrl: The control to (de)activate. @@ -743,7 +759,15 @@ void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);* This function assumes that the control handler is not locked and will * take the lock itself. */ -void v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed); +static inline void v4l2_ctrl_grab (struct v4l2_ctrl *ctrl,bool grabbed) +{ +if (!ctrl) +return ; + +v4l2_ctrl_lock (ctrl); +__v4l2_ctrl_grab (ctrl, grabbed); +v4l2_ctrl_unlock (ctrl); +}/** *__v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range()