From patchwork Tue Mar 8 17:18:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550060 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89AABC433EF for ; Tue, 8 Mar 2022 17:19:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349014AbiCHRUr (ORCPT ); Tue, 8 Mar 2022 12:20:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348921AbiCHRU2 (ORCPT ); Tue, 8 Mar 2022 12:20:28 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9463A53707; Tue, 8 Mar 2022 09:19:18 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id w4so22863337edc.7; Tue, 08 Mar 2022 09:19:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f7/gAw+DbnZtTNdfpuzCiVdL6RMHX2i8psNGo9On2wE=; b=lZBLD5iJRHwna6Pu9qZ7/2APxDtkJaKEHwNbE6+HMjiGuMvomc/1zMzNkJChwYwOUC wh89YneS2YEvD1/3E6YiYRkJbMfG14PYEDSfnKDOcxnRP86SWcxS+yh4s7WyQE2Mitu1 5RtmU2GidWXd6f7WiJashE9Qqgssg/o/2ZRHgnj8zz4nFdcijcP2eAfyDFXkg/VziKBp fqFqBR0KEsNPf44Sn9hQfNdXuWNfTxuGjgHy8vmo3vjX+y4J4MTqLR7vzKlkakM9kzyh AUOXbd9aDkpQYqCJqZ+9+RAw+U9zUkeKnbcGsk+a55lXbgYXhRF0rEFrElYYIkfkmzSO Jb8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f7/gAw+DbnZtTNdfpuzCiVdL6RMHX2i8psNGo9On2wE=; b=g17PkaMpt9TAdx2L0O3mzOxEf1emtmZgiIHHQJpoVLDbo8n1q6qUBNY70sE7DeJ2NY xkV/R84n4Mj5Ce2d7xcXo/7XH9/sfV5oyP/ufIcyGuWoW6n3KHVGO1rCkyjPpF0V9cw5 373QoDst4MsN1oBC8UoM0W6BO7+qo6/BYpH3Cx/jSmeLaBvEUvh6+QWxhZYoMKwv6rbr aLe7hMcV2VZCAYfIR+aAfjZcv7Cx6zxHuEUWIsFq+8NiGffS2aZuSmfu9dj4+9+E0hnc 6rn9wIuqjLgLKe/vd2AZDJfWNp86gXWQcXrskBvynl4k1jk2dei9eSXgcwl56qMK2zik O9Lw== X-Gm-Message-State: AOAM531qaDBFcffJL6y41oZRcxWqIfeUB2x4lRV103jaUA1aMSkVuCXi zW1emPXMKCHBcpahNcWyLP8= X-Google-Smtp-Source: ABdhPJwKkX7DtmzDeIcS50PuB5Lq/wQhby7A+8VQURHoYiYvl5JNbYQ/SGWLW3UA2emPereAn1aNbw== X-Received: by 2002:a05:6402:268a:b0:416:7ed0:3f86 with SMTP id w10-20020a056402268a00b004167ed03f86mr589970edd.255.1646759954659; Tue, 08 Mar 2022 09:19:14 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:14 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 08/26] usb: gadget: lpc32xx_udc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:00 +0100 Message-Id: <20220308171818.384491-9-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/lpc32xx_udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c index a25d01c89564..6117ae8e7242 100644 --- a/drivers/usb/gadget/udc/lpc32xx_udc.c +++ b/drivers/usb/gadget/udc/lpc32xx_udc.c @@ -1830,7 +1830,7 @@ static int lpc32xx_ep_queue(struct usb_ep *_ep, static int lpc32xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct lpc32xx_ep *ep; - struct lpc32xx_request *req; + struct lpc32xx_request *req = NULL, *iter; unsigned long flags; ep = container_of(_ep, struct lpc32xx_ep, ep); @@ -1840,11 +1840,13 @@ static int lpc32xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&ep->udc->lock, flags); /* make sure it's actually queued on this endpoint */ - list_for_each_entry(req, &ep->queue, queue) { - if (&req->req == _req) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { spin_unlock_irqrestore(&ep->udc->lock, flags); return -EINVAL; }