aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans Verkuil <hans.verkuil@cisco.com>2011-06-07 03:40:04 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-07-27 16:53:16 -0400
commit37cd3b73683f15f1b6313d0de476726aa0942a75 (patch)
treec947c202742fb4e86434e3231f12b929120e5c88 /drivers/media
parent54c911eb919b44b178bda67564f274197872bd04 (diff)
[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: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/video/v4l2-ctrls.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c
index 3f2a0c5a1c3a..d9e04394c856 100644
--- a/drivers/media/video/v4l2-ctrls.c
+++ b/drivers/media/video/v4l2-ctrls.c
@@ -1450,8 +1450,7 @@ EXPORT_SYMBOL(v4l2_subdev_querymenu);
1450 Find the controls in the control array and do some basic checks. */ 1450 Find the controls in the control array and do some basic checks. */
1451static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, 1451static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1452 struct v4l2_ext_controls *cs, 1452 struct v4l2_ext_controls *cs,
1453 struct ctrl_helper *helpers, 1453 struct ctrl_helper *helpers)
1454 bool try)
1455{ 1454{
1456 u32 i; 1455 u32 i;
1457 1456
@@ -1460,8 +1459,7 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1460 struct v4l2_ctrl *ctrl; 1459 struct v4l2_ctrl *ctrl;
1461 u32 id = c->id & V4L2_CTRL_ID_MASK; 1460 u32 id = c->id & V4L2_CTRL_ID_MASK;
1462 1461
1463 if (try) 1462 cs->error_idx = i;
1464 cs->error_idx = i;
1465 1463
1466 if (cs->ctrl_class && V4L2_CTRL_ID2CLASS(id) != cs->ctrl_class) 1464 if (cs->ctrl_class && V4L2_CTRL_ID2CLASS(id) != cs->ctrl_class)
1467 return -EINVAL; 1465 return -EINVAL;
@@ -1554,7 +1552,8 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs
1554 return -ENOMEM; 1552 return -ENOMEM;
1555 } 1553 }
1556 1554
1557 ret = prepare_ext_ctrls(hdl, cs, helpers, false); 1555 ret = prepare_ext_ctrls(hdl, cs, helpers);
1556 cs->error_idx = cs->count;
1558 1557
1559 for (i = 0; !ret && i < cs->count; i++) 1558 for (i = 0; !ret && i < cs->count; i++)
1560 if (helpers[i].ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY) 1559 if (helpers[i].ctrl->flags & V4L2_CTRL_FLAG_WRITE_ONLY)
@@ -1701,12 +1700,10 @@ static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1701 unsigned i, j; 1700 unsigned i, j;
1702 int ret = 0; 1701 int ret = 0;
1703 1702
1704 cs->error_idx = cs->count;
1705 for (i = 0; i < cs->count; i++) { 1703 for (i = 0; i < cs->count; i++) {
1706 struct v4l2_ctrl *ctrl = helpers[i].ctrl; 1704 struct v4l2_ctrl *ctrl = helpers[i].ctrl;
1707 1705
1708 if (!set) 1706 cs->error_idx = i;
1709 cs->error_idx = i;
1710 1707
1711 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY) 1708 if (ctrl->flags & V4L2_CTRL_FLAG_READ_ONLY)
1712 return -EACCES; 1709 return -EACCES;
@@ -1724,11 +1721,10 @@ static int try_or_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1724 struct v4l2_ctrl *ctrl = helpers[i].ctrl; 1721 struct v4l2_ctrl *ctrl = helpers[i].ctrl;
1725 struct v4l2_ctrl *master = ctrl->cluster[0]; 1722 struct v4l2_ctrl *master = ctrl->cluster[0];
1726 1723
1727 cs->error_idx = i;
1728
1729 if (helpers[i].handled) 1724 if (helpers[i].handled)
1730 continue; 1725 continue;
1731 1726
1727 cs->error_idx = i;
1732 v4l2_ctrl_lock(ctrl); 1728 v4l2_ctrl_lock(ctrl);
1733 1729
1734 /* Reset the 'is_new' flags of the cluster */ 1730 /* Reset the 'is_new' flags of the cluster */
@@ -1777,12 +1773,11 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1777 if (!helpers) 1773 if (!helpers)
1778 return -ENOMEM; 1774 return -ENOMEM;
1779 } 1775 }
1780 ret = prepare_ext_ctrls(hdl, cs, helpers, !set); 1776 ret = prepare_ext_ctrls(hdl, cs, helpers);
1781 if (ret)
1782 goto free;
1783 1777
1784 /* First 'try' all controls and abort on error */ 1778 /* First 'try' all controls and abort on error */
1785 ret = try_or_set_ext_ctrls(hdl, cs, helpers, false); 1779 if (!ret)
1780 ret = try_or_set_ext_ctrls(hdl, cs, helpers, false);
1786 /* If this is a 'set' operation and the initial 'try' failed, 1781 /* If this is a 'set' operation and the initial 'try' failed,
1787 then set error_idx to count to tell the application that no 1782 then set error_idx to count to tell the application that no
1788 controls changed value yet. */ 1783 controls changed value yet. */
@@ -1795,7 +1790,6 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl,
1795 ret = try_or_set_ext_ctrls(hdl, cs, helpers, true); 1790 ret = try_or_set_ext_ctrls(hdl, cs, helpers, true);
1796 } 1791 }
1797 1792
1798free:
1799 if (cs->count > ARRAY_SIZE(helper)) 1793 if (cs->count > ARRAY_SIZE(helper))
1800 kfree(helpers); 1794 kfree(helpers);
1801 return ret; 1795 return ret;