[media] v4l: ctrls: Provide an unlocked variant of v4l2_ctrl_modify_range()
authorSakari Ailus <sakari.ailus@linux.intel.com>
Thu, 12 Jun 2014 16:09:40 +0000 (13:09 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Mon, 21 Jul 2014 22:44:45 +0000 (19:44 -0300)
Drivers may use the v4l2_ctrl_modify_range() internally as part of other
operations that need to be both serialised using a driver's lock which can
also be used to serialise access to the control handler. Provide an unlocked
version of the function, __v4l2_ctrl_modify_range() which then may be used
by drivers for the purpose.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/v4l2-core/v4l2-ctrls.c
include/media/v4l2-ctrls.h

index 8552c832074a45c35fc807bd2bf6e5478b29b081..9cd978334b89d33fb2fce057514a548deefddc2b 100644 (file)
@@ -3213,12 +3213,14 @@ void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void
 }
 EXPORT_SYMBOL(v4l2_ctrl_notify);
 
-int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
+int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
                        s64 min, s64 max, u64 step, s64 def)
 {
        int ret;
        struct v4l2_ext_control c;
 
+       lockdep_assert_held(ctrl->handler->lock);
+
        switch (ctrl->type) {
        case V4L2_CTRL_TYPE_INTEGER:
        case V4L2_CTRL_TYPE_INTEGER64:
@@ -3237,7 +3239,6 @@ int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
        default:
                return -EINVAL;
        }
-       v4l2_ctrl_lock(ctrl);
        ctrl->minimum = min;
        ctrl->maximum = max;
        ctrl->step = step;
@@ -3249,10 +3250,9 @@ int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
                ret = set_ctrl(NULL, ctrl, &c, V4L2_EVENT_CTRL_CH_RANGE);
        else
                send_event(NULL, ctrl, V4L2_EVENT_CTRL_CH_RANGE);
-       v4l2_ctrl_unlock(ctrl);
        return ret;
 }
-EXPORT_SYMBOL(v4l2_ctrl_modify_range);
+EXPORT_SYMBOL(__v4l2_ctrl_modify_range);
 
 static int v4l2_ctrl_add_event(struct v4l2_subscribed_event *sev, unsigned elems)
 {
index 4546233a9a3d1d188540e7ae299128f49ef11d56..5d1a30ca29af1e1bcfa478b4076e1a74afba740f 100644 (file)
@@ -620,6 +620,11 @@ void v4l2_ctrl_activate(struct v4l2_ctrl *ctrl, bool active);
   */
 void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
 
+
+/** __v4l2_ctrl_modify_range() - Unlocked variant of v4l2_ctrl_modify_range() */
+int __v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
+                            s64 min, s64 max, u64 step, s64 def);
+
 /** v4l2_ctrl_modify_range() - Update the range of a control.
   * @ctrl:     The control to update.
   * @min:      The control's minimum value.
@@ -637,8 +642,17 @@ void v4l2_ctrl_grab(struct v4l2_ctrl *ctrl, bool grabbed);
   * This function assumes that the control handler is not locked and will
   * take the lock itself.
   */
-int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
-                       s64 min, s64 max, u64 step, s64 def);
+static inline int v4l2_ctrl_modify_range(struct v4l2_ctrl *ctrl,
+                                        s64 min, s64 max, u64 step, s64 def)
+{
+       int rval;
+
+       v4l2_ctrl_lock(ctrl);
+       rval = __v4l2_ctrl_modify_range(ctrl, min, max, step, def);
+       v4l2_ctrl_unlock(ctrl);
+
+       return rval;
+}
 
 /** v4l2_ctrl_notify() - Function to set a notify callback for a control.
   * @ctrl:     The control.