Skip to content

Commit 9ea1b7a

Browse files
Hans Verkuilmchehab
authored andcommitted
[media] v4l2-ctrls: compare values only once
When setting a control the control's new value is compared to the current value twice: once by new_to_cur(), once by cluster_changed(). Not a big deal when dealing with simple values, but it can be a problem when dealing with compound types or arrays. So fix this: cluster_changed() sets the has_changed flag, which is used by new_to_cur() instead of having to do another compare. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
1 parent 000e4f9 commit 9ea1b7a

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

‎drivers/media/v4l2-core/v4l2-ctrls.c‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,8 +1424,11 @@ static void new_to_cur(struct v4l2_fh *fh, struct v4l2_ctrl *ctrl, u32 ch_flags)
14241424

14251425
if (ctrl == NULL)
14261426
return;
1427-
changed = !ctrl->type_ops->equal(ctrl, ctrl->p_cur, ctrl->p_new);
1428-
ptr_to_ptr(ctrl, ctrl->p_new, ctrl->p_cur);
1427+
1428+
/* has_changed is set by cluster_changed */
1429+
changed = ctrl->has_changed;
1430+
if (changed)
1431+
ptr_to_ptr(ctrl, ctrl->p_new, ctrl->p_cur);
14291432

14301433
if (ch_flags & V4L2_EVENT_CTRL_CH_FLAGS) {
14311434
/* Note: CH_FLAGS is only set for auto clusters. */
@@ -1462,17 +1465,19 @@ static void cur_to_new(struct v4l2_ctrl *ctrl)
14621465
value that differs from the current value. */
14631466
static int cluster_changed(struct v4l2_ctrl *master)
14641467
{
1465-
int diff = 0;
1468+
bool changed = false;
14661469
int i;
14671470

1468-
for (i = 0; !diff && i < master->ncontrols; i++) {
1471+
for (i = 0; i < master->ncontrols; i++) {
14691472
struct v4l2_ctrl *ctrl = master->cluster[i];
14701473

14711474
if (ctrl == NULL)
14721475
continue;
1473-
diff = !ctrl->type_ops->equal(ctrl, ctrl->p_cur, ctrl->p_new);
1476+
ctrl->has_changed = !ctrl->type_ops->equal(ctrl,
1477+
ctrl->p_cur, ctrl->p_new);
1478+
changed |= ctrl->has_changed;
14741479
}
1475-
return diff;
1480+
return changed;
14761481
}
14771482

14781483
/* Control range checking */

‎include/media/v4l2-ctrls.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ typedef void (*v4l2_ctrl_notify_fnc)(struct v4l2_ctrl *ctrl, void *priv);
9696
* @is_new: Set when the user specified a new value for this control. It
9797
* is also set when called from v4l2_ctrl_handler_setup. Drivers
9898
* should never set this flag.
99+
* @has_changed: Set when the current value differs from the new value. Drivers
100+
* should never use this flag.
99101
* @is_private: If set, then this control is private to its handler and it
100102
* will not be added to any other handlers. Drivers can set
101103
* this flag.
@@ -158,6 +160,7 @@ struct v4l2_ctrl {
158160
unsigned int done:1;
159161

160162
unsigned int is_new:1;
163+
unsigned int has_changed:1;
161164
unsigned int is_private:1;
162165
unsigned int is_auto:1;
163166
unsigned int is_int:1;

0 commit comments

Comments
 (0)