From patchwork Tue Jun 7 15:05:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 857402 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p57F5e6Y010205 for ; Tue, 7 Jun 2011 15:06:08 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755069Ab1FGPFd (ORCPT ); Tue, 7 Jun 2011 11:05:33 -0400 Received: from smtp-vbr1.xs4all.nl ([194.109.24.21]:2212 "EHLO smtp-vbr1.xs4all.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754825Ab1FGPFb (ORCPT ); Tue, 7 Jun 2011 11:05:31 -0400 Received: from tschai.lan (215.80-203-102.nextgentel.com [80.203.102.215]) (authenticated bits=0) by smtp-vbr1.xs4all.nl (8.13.8/8.13.8) with ESMTP id p57F5QqM037616 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 7 Jun 2011 17:05:28 +0200 (CEST) (envelope-from hverkuil@xs4all.nl) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Hans Verkuil Subject: [RFCv3 PATCH 02/18] v4l2-ctrls: simplify error_idx handling. Date: Tue, 7 Jun 2011 17:05:07 +0200 Message-Id: <5389151f22127fac05adbf276eb41395d215850e.1307458245.git.hans.verkuil@cisco.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1307459123-17810-1-git-send-email-hverkuil@xs4all.nl> References: <1307459123-17810-1-git-send-email-hverkuil@xs4all.nl> In-Reply-To: References: X-Virus-Scanned: by XS4ALL Virus Scanner Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 07 Jun 2011 15:06:09 +0000 (UTC) From: Hans Verkuil 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 --- drivers/media/video/v4l2-ctrls.c | 24 +++++++++--------------- 1 files changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c index 3f2a0c5..d9e0439 100644 --- a/drivers/media/video/v4l2-ctrls.c +++ b/drivers/media/video/v4l2-ctrls.c @@ -1450,8 +1450,7 @@ EXPORT_SYMBOL(v4l2_subdev_querymenu); Find the controls in the control array and do some basic checks. */ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs, - struct ctrl_helper *helpers, - bool try) + struct ctrl_helper *helpers) { u32 i; @@ -1460,8 +1459,7 @@ static int prepare_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ctrl *ctrl; 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) return -EINVAL; @@ -1554,7 +1552,8 @@ int v4l2_g_ext_ctrls(struct v4l2_ctrl_handler *hdl, struct v4l2_ext_controls *cs 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++) 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, unsigned i, j; int ret = 0; - cs->error_idx = cs->count; for (i = 0; i < cs->count; i++) { 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) return -EACCES; @@ -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 *master = ctrl->cluster[0]; - cs->error_idx = i; - if (helpers[i].handled) continue; + cs->error_idx = i; v4l2_ctrl_lock(ctrl); /* Reset the 'is_new' flags of the cluster */ @@ -1777,12 +1773,11 @@ static int try_set_ext_ctrls(struct v4l2_ctrl_handler *hdl, if (!helpers) return -ENOMEM; } - ret = prepare_ext_ctrls(hdl, cs, helpers, !set); - if (ret) - goto free; + ret = prepare_ext_ctrls(hdl, cs, helpers); /* First 'try' all controls and abort on error */ - ret = try_or_set_ext_ctrls(hdl, cs, helpers, false); + if (!ret) + ret = try_or_set_ext_ctrls(hdl, cs, helpers, false); /* If this is a 'set' operation and the initial 'try' failed, then set error_idx to count to tell the application that no controls changed value yet. */ @@ -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); } -free: if (cs->count > ARRAY_SIZE(helper)) kfree(helpers); return ret;