From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A84ADC433DF for ; Sat, 8 Aug 2020 20:40:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AB84206C3 for ; Sat, 8 Aug 2020 20:40:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BK/j4gLQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726321AbgHHUk1 (ORCPT ); Sat, 8 Aug 2020 16:40:27 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:36902 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726069AbgHHUk1 (ORCPT ); Sat, 8 Aug 2020 16:40:27 -0400 Received: from pendragon.ideasonboard.com (85-76-78-184-nat.elisa-mobile.fi [85.76.78.184]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DF003F9; Sat, 8 Aug 2020 22:40:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1596919224; bh=vIReoEoXrYFf0pZEs/Z6RMS6MgwBIuS/weoocSp8iFM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BK/j4gLQ26C7kY2tV3PpvdTDzj7lhemCpLdn64YaGk/1HN4w3zssi31QzfsXCqpco tjLkdruPned3KDD2jGclOkf9fK/WNEV1gZvP8sjcZXDmCru5DGSnDh7bNTYIB35lTm yDA/SREk9c0Lo3VjH32GrNnaYQ4+KPlRTgYS124U= Date: Sat, 8 Aug 2020 23:40:07 +0300 From: Laurent Pinchart To: "Daniel W. S. Almeida" Cc: skhan@linuxfoundation.org, Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 03/20] media: usb: uvc_ctrl.c: add temp variable for list iteration Message-ID: <20200808204007.GI6186@pendragon.ideasonboard.com> References: <20200807083548.204360-3-dwlsalmeida@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200807083548.204360-3-dwlsalmeida@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel, Thank you for the patch. On Fri, Aug 07, 2020 at 05:35:30AM -0300, Daniel W. S. Almeida wrote: > From: "Daniel W. S. Almeida" > > 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 > --- > 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; cursor doesn't have to be initialized to NULL. It may be a style preference, but instead of a cursor variable that doesn't tell in its name what it refers to, I'd prefer a bool found = false; > 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) { All this would keep using entity. > + entity = cursor; And this would be replaced with found = true; > break; > + } > } > > - if (entity->id != xqry->unit) { > + if (!entity || entity->id != xqry->unit) { The second part of the check isn't needed, it was only meant to check if the entity has been found. Here, we'd have if (!found) { I'f you're OK with these changes there's no need to resubmit, I can update when applying. Please let me know how you'd like to proceed. > uvc_trace(UVC_TRACE_CONTROL, "Extension unit %u not found.\n", > xqry->unit); > return -ENOENT; -- Regards, Laurent Pinchart