linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel W. S. Almeida" <dwlsalmeida@gmail.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: skhan@linuxfoundation.org,
	"Daniel W. S. Almeida" <dwlsalmeida@gmail.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 04/20] media: uvc: uvc_v4l2.c: add temp variable for list iteration
Date: Fri,  7 Aug 2020 05:35:31 -0300	[thread overview]
Message-ID: <20200807083548.204360-4-dwlsalmeida@gmail.com> (raw)

From: "Daniel W. S. Almeida" <dwlsalmeida@gmail.com>

Fixes the following coccinelle reports:

drivers/media/usb/uvc/uvc_v4l2.c:840:8-13:
ERROR: invalid reference to the index variable of the iterator on line 836

drivers/media/usb/uvc/uvc_v4l2.c:851:5-10:
ERROR: invalid reference to the index variable of the iterator on line 843

drivers/media/usb/uvc/uvc_v4l2.c:851:22-27:
ERROR: invalid reference to the index variable of the iterator on line 843

Byy introducing a temporary variable for list iteration.

Found using - Coccinelle (http://coccinelle.lip6.fr)

Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
---
 drivers/media/usb/uvc/uvc_v4l2.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 0335e69b70ab..7205ef13c2e1 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -826,6 +826,7 @@ static int uvc_ioctl_enum_input(struct file *file, void *fh,
 	struct uvc_video_chain *chain = handle->chain;
 	const struct uvc_entity *selector = chain->selector;
 	struct uvc_entity *iterm = NULL;
+	struct uvc_entity *cursor = NULL;
 	u32 index = input->index;
 	int pin = 0;
 
@@ -833,18 +834,22 @@ static int uvc_ioctl_enum_input(struct file *file, void *fh,
 	    (chain->dev->quirks & UVC_QUIRK_IGNORE_SELECTOR_UNIT)) {
 		if (index != 0)
 			return -EINVAL;
-		list_for_each_entry(iterm, &chain->entities, chain) {
-			if (UVC_ENTITY_IS_ITERM(iterm))
+		list_for_each_entry(cursor, &chain->entities, chain) {
+			if (UVC_ENTITY_IS_ITERM(cursor)){
+				iterm = cursor;
 				break;
+			}
 		}
 		pin = iterm->id;
 	} else if (index < selector->bNrInPins) {
 		pin = selector->baSourceID[index];
-		list_for_each_entry(iterm, &chain->entities, chain) {
-			if (!UVC_ENTITY_IS_ITERM(iterm))
+		list_for_each_entry(cursor, &chain->entities, chain) {
+			if (!UVC_ENTITY_IS_ITERM(cursor))
 				continue;
-			if (iterm->id == pin)
+			if (cursor->id == pin) {
+				iterm = cursor;
 				break;
+			}
 		}
 	}
 
@@ -1519,4 +1524,3 @@ const struct v4l2_file_operations uvc_fops = {
 	.get_unmapped_area = uvc_v4l2_get_unmapped_area,
 #endif
 };
-
-- 
2.28.0


             reply	other threads:[~2020-08-07  8:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-07  8:35 Daniel W. S. Almeida [this message]
2020-08-08 20:45 ` [PATCH 04/20] media: uvc: uvc_v4l2.c: add temp variable for list iteration Laurent Pinchart
2020-08-10 13:10   ` Daniel W. S. Almeida

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=20200807083548.204360-4-dwlsalmeida@gmail.com \
    --to=dwlsalmeida@gmail.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=skhan@linuxfoundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).