Commit 37cd3b73 authored by Hans Verkuil's avatar Hans Verkuil Committed by Mauro Carvalho Chehab

[media] v4l2-ctrls: simplify error_idx handling

The lower-level prepare functions just set error_idx for each control that
might have an error. The high-level functions will override this with
cs->count in the get and set cases. Only try will keep the error_idx.
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 54c911eb
...@@ -1450,8 +1450,7 @@ EXPORT_SYMBOL(v4l2_subdev_querymenu); ...@@ -1450,8 +1450,7 @@ EXPORT_SYMBOL(v4l2_subdev_querymenu);
Find the controls in the control array and do some basic checks. */ Find the controls in the control array and do some basic checks. */
static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
struct v4l2_ext_controls *cs, struct v4l2_ext_controls *cs,
struct ctrl_helper *helpers, struct ctrl_helper *helpers)
bool try)
{ {
u32 i; u32 i;
...@@ -1460,7 +1459,6 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, ...@@ -1460,7 +1459,6 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl *ctrl; struct v4l2_ctrl *ctrl;
u32 id = c->id & V4L2_CTRL_ID_MASK; u32 id = c->id & V4L2_CTRL_ID_MASK;
if (try)
cs->error_idx = i; cs->error_idx = i;
if (cs->ctrl_class && V4L2_CTRL_ID2CLASS(id) != cs->ctrl_class) if (cs->ctrl_class && V4L2_CTRL_ID2CLASS(id) != cs->ctrl_class)
...@@ -1554,7 +1552,8 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs ...@@ -1554,7 +1552,8 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs
return -ENOMEM; return -ENOMEM;
} }
ret = prepare_ext_ctrls(hdl, cs, helpers, false); ret = prepare_ext_ctrls(hdl, cs, helpers);
cs->error_idx = cs->count;
for (i = 0; !ret && i < cs->count; i++) for (i = 0; !ret && i < cs->count; i++)
if (helpers[i].ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) if (helpers[i].ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
...@@ -1701,11 +1700,9 @@ static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, ...@@ -1701,11 +1700,9 @@ static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
unsigned i, j; unsigned i, j;
int ret = 0; int ret = 0;
cs->error_idx = cs->count;
for (i = 0; i < cs->count; i++) { for (i = 0; i < cs->count; i++) {
struct v4l2_ctrl *ctrl = helpers[i].ctrl; struct v4l2_ctrl *ctrl = helpers[i].ctrl;
if (!set)
cs->error_idx = i; cs->error_idx = i;
if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
...@@ -1724,11 +1721,10 @@ static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, ...@@ -1724,11 +1721,10 @@ static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
struct v4l2_ctrl *ctrl = helpers[i].ctrl; struct v4l2_ctrl *ctrl = helpers[i].ctrl;
struct v4l2_ctrl *master = ctrl->cluster[0]; struct v4l2_ctrl *master = ctrl->cluster[0];
cs->error_idx = i;
if (helpers[i].handled) if (helpers[i].handled)
continue; continue;
cs->error_idx = i;
v4l2_ctrl_lock(ctrl); v4l2_ctrl_lock(ctrl);
/* Reset the 'is_new' flags of the cluster */ /* Reset the 'is_new' flags of the cluster */
...@@ -1777,11 +1773,10 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, ...@@ -1777,11 +1773,10 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
if (!helpers) if (!helpers)
return -ENOMEM; return -ENOMEM;
} }
ret = prepare_ext_ctrls(hdl, cs, helpers, !set); ret = prepare_ext_ctrls(hdl, cs, helpers);
if (ret)
goto free;
/* First 'try' all controls and abort on error */ /* First 'try' all controls and abort on error */
if (!ret)
ret = try_or_set_ext_ctrls(hdl, cs, helpers, false); ret = try_or_set_ext_ctrls(hdl, cs, helpers, false);
/* If this is a 'set' operation and the initial 'try' failed, /* If this is a 'set' operation and the initial 'try' failed,
then set error_idx to count to tell the application that no then set error_idx to count to tell the application that no
...@@ -1795,7 +1790,6 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, ...@@ -1795,7 +1790,6 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
ret = try_or_set_ext_ctrls(hdl, cs, helpers, true); ret = try_or_set_ext_ctrls(hdl, cs, helpers, true);
} }
free:
if (cs->count > ARRAY_SIZE(helper)) if (cs->count > ARRAY_SIZE(helper))
kfree(helpers); kfree(helpers);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment