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 03/20] media: usb: uvc_ctrl.c: add temp variable for list iteration
Date: Fri, 7 Aug 2020 05:35:30 -0300 [thread overview]
Message-ID: <20200807083548.204360-3-dwlsalmeida@gmail.com> (raw)
From: "Daniel W. S. Almeida" <dwlsalmeida@gmail.com>
Fixes the following coccinelle report:
drivers/media/usb/uvc/uvc_ctrl.c:1860:5-11:
ERROR: invalid reference to the index variable of the iterator on line 1854
By introducing a temporary variable to iterate the list.
Do not dereference the 'entity' pointer if it is not found in the list.
Found using - Coccinelle (http://coccinelle.lip6.fr)
Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
---
drivers/media/usb/uvc/uvc_ctrl.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c
index e399b9fad757..567bdedc2ff2 100644
--- a/drivers/media/usb/uvc/uvc_ctrl.c
+++ b/drivers/media/usb/uvc/uvc_ctrl.c
@@ -1842,7 +1842,8 @@ static int uvc_ctrl_init_xu_ctrl(struct uvc_device *dev,
int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
struct uvc_xu_control_query *xqry)
{
- struct uvc_entity *entity;
+ struct uvc_entity *entity = NULL;
+ struct uvc_entity *cursor = NULL;
struct uvc_control *ctrl;
unsigned int i, found = 0;
u32 reqflags;
@@ -1851,13 +1852,15 @@ int uvc_xu_ctrl_query(struct uvc_video_chain *chain,
int ret;
/* Find the extension unit. */
- list_for_each_entry(entity, &chain->entities, chain) {
- if (UVC_ENTITY_TYPE(entity) == UVC_VC_EXTENSION_UNIT &&
- entity->id == xqry->unit)
+ list_for_each_entry(cursor, &chain->entities, chain) {
+ if (UVC_ENTITY_TYPE(cursor) == UVC_VC_EXTENSION_UNIT &&
+ cursor->id == xqry->unit) {
+ entity = cursor;
break;
+ }
}
- if (entity->id != xqry->unit) {
+ if (!entity || entity->id != xqry->unit) {
uvc_trace(UVC_TRACE_CONTROL, "Extension unit %u not found.\n",
xqry->unit);
return -ENOENT;
--
2.28.0
next reply other threads:[~2020-08-07 8:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-07 8:35 Daniel W. S. Almeida [this message]
2020-08-08 20:40 ` Laurent Pinchart
2020-08-08 20:47 ` Laurent Pinchart
2020-08-10 12:57 ` 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-3-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
all inboxes | Powered by JetHome®