All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ricardo Ribalda <ribalda@chromium.org>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
	 Yasunari Takiguchi <Yasunari.Takiguchi@sony.com>,
	 Jean-Christophe Trotin <jean-christophe.trotin@foss.st.com>,
	 Lars-Peter Clausen <lars@metafoo.de>,
	 Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>,
	linux-media@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-input@vger.kernel.org,
	 Ricardo Ribalda <ribalda@chromium.org>
Subject: [PATCH 4/6] media: v4l2-ctrls-core.c: Do not use iterator outside loop
Date: Wed, 10 Apr 2024 21:54:41 +0000	[thread overview]
Message-ID: <20240410-smatch-v1-4-785d009a852b@chromium.org> (raw)
In-Reply-To: <20240410-smatch-v1-0-785d009a852b@chromium.org>

Simplify a bit the code introducing a new variable for iterating through
the control list.

It also makes smatch happy:

drivers/media/v4l2-core/v4l2-ctrls-api.c:1091 v4l2_query_ext_ctrl() warn: iterator used outside loop: 'ref'

Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
 drivers/media/v4l2-core/v4l2-ctrls-api.c | 33 ++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/drivers/media/v4l2-core/v4l2-ctrls-api.c b/drivers/media/v4l2-core/v4l2-ctrls-api.c
index d9a422017bd9d..42b7a45bfa79c 100644
--- a/drivers/media/v4l2-core/v4l2-ctrls-api.c
+++ b/drivers/media/v4l2-core/v4l2-ctrls-api.c
@@ -1052,35 +1052,40 @@ int v4l2_query_ext_ctrl(struct v4l2_ctrl_handler *hdl, struct v4l2_query_ext_ctr
 		if (id >= node2id(hdl->ctrl_refs.prev)) {
 			ref = NULL; /* Yes, so there is no next control */
 		} else if (ref) {
+			struct v4l2_ctrl_ref *pos  = ref;
+
 			/*
 			 * We found a control with the given ID, so just get
 			 * the next valid one in the list.
 			 */
-			list_for_each_entry_continue(ref, &hdl->ctrl_refs, node) {
-				is_compound = ref->ctrl->is_array ||
-					ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
-				if (id < ref->ctrl->id &&
-				    (is_compound & mask) == match)
+			ref = NULL;
+			list_for_each_entry_continue(pos, &hdl->ctrl_refs, node) {
+				is_compound = pos->ctrl->is_array ||
+					pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
+				if (id < pos->ctrl->id &&
+				    (is_compound & mask) == match) {
+					ref = pos;
 					break;
+				}
 			}
-			if (&ref->node == &hdl->ctrl_refs)
-				ref = NULL;
 		} else {
+			struct v4l2_ctrl_ref *pos;
+
 			/*
 			 * No control with the given ID exists, so start
 			 * searching for the next largest ID. We know there
 			 * is one, otherwise the first 'if' above would have
 			 * been true.
 			 */
-			list_for_each_entry(ref, &hdl->ctrl_refs, node) {
-				is_compound = ref->ctrl->is_array ||
-					ref->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
-				if (id < ref->ctrl->id &&
-				    (is_compound & mask) == match)
+			list_for_each_entry(pos, &hdl->ctrl_refs, node) {
+				is_compound = pos->ctrl->is_array ||
+					pos->ctrl->type >= V4L2_CTRL_COMPOUND_TYPES;
+				if (id < pos->ctrl->id &&
+				    (is_compound & mask) == match) {
+					ref = pos;
 					break;
+				}
 			}
-			if (&ref->node == &hdl->ctrl_refs)
-				ref = NULL;
 		}
 	}
 	mutex_unlock(hdl->lock);

-- 
2.44.0.478.gd926399ef9-goog


  parent reply	other threads:[~2024-04-10 21:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 21:54 [PATCH 0/6] media: Fix warnings for smatch and sparse Ricardo Ribalda
2024-04-10 21:54 ` [PATCH 1/6] media: usb: siano: Fix allocation of urbs Ricardo Ribalda
2024-04-15 10:08   ` Hans Verkuil
2024-04-15 11:47     ` Hans Verkuil
2024-04-10 21:54 ` [PATCH 2/6] media: cxd2880: Replaze kmalloc with kzalloc Ricardo Ribalda
2024-04-10 21:54 ` [PATCH 3/6] media: platform: sti: hva: clk_unprepare unconditionally Ricardo Ribalda
2024-04-10 21:54 ` Ricardo Ribalda [this message]
2024-04-10 21:54 ` [PATCH 5/6] media: adv7180: Only request valids IRQs Ricardo Ribalda
2024-04-10 21:54 ` [PATCH 6/6] media: touchscreen: sur40: convert le16 to cpu before use Ricardo Ribalda
2024-04-15 21:52   ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240410-smatch-v1-4-785d009a852b@chromium.org \
    --to=ribalda@chromium.org \
    --cc=Yasunari.Takiguchi@sony.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=jean-christophe.trotin@foss.st.com \
    --cc=lars@metafoo.de \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.