Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1530354pxp; Sun, 6 Mar 2022 18:15:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQLQucHH10cJ61T3DzAYw7LDdBxKwmAjdoQCvN94ayupGuAIn2rEbujRVMUMXy3SxnVxVk X-Received: by 2002:a63:8ac7:0:b0:37c:8b82:dc3f with SMTP id y190-20020a638ac7000000b0037c8b82dc3fmr8294798pgd.167.1646619305116; Sun, 06 Mar 2022 18:15:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646619305; cv=none; d=google.com; s=arc-20160816; b=I7US1B0lJ9/9SBL0cvDCEo8G3hDkOdwSsct7TJkpYkn+Twn2CllYpaOZZO/qekWDWz ltRinGSLwNAI6K5axPBnY2ehOwloODt0j4GN1zHUGl5sf5gzfUWQpZG6g4FcADT8lEss JDGr9aJFaN+S4XhLKmCS2f8J1TPxn40xWn7zB40seyzODDjUlmMxDUlHVDi68XrmxMAt me97DyEPaaMjz8WRNFuPNWQXBwPOMOrZRMxmxcR5bsypND/FPTaXMlf4H1t9aeF6IqlX UQWlhPOzYBozTUOfAqt4xw7itpjZbTpteNs3GzEWqoHKh/aIZdwf0/f3a7aPioSoT4Lb qpPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9KJD2l59oR//tzv+KJB1jDWKlj1X2HYA5Vg/4RaHEkw=; b=FNOR5mpKKWVid15Ybm47R+0EBZMZZ1DKTh8UmwQKAPl74DM4QjtIbrg9+7kDpplUxy 60PH9xzoP+7BOR71QwpIfq3SolkhgtZqRNApvuFPzh6iMY2ysET04ya6jhBtyT4txFLg o4yn8r+9dpS8eFkpYdcLuQnTCBWthBCp158DLOF0vFtDfWgEATH5c/shxPkfq1Muc8zv SiVuDRwKZPR4Lbj3ynjTKrVfSz5ULfM7LBtgJXo5idjW68QNJjBdyT132AW1bxqXCQkn iJCFLLk0lf+ttGTZIHb73K+HNlGZeH823DnJZJHrDoPiYI22bPyI4MnZqHY2/gUKStHm gdww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bBSm7yrp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m11-20020a65530b000000b00378a8c76238si11492234pgq.414.2022.03.06.18.14.49; Sun, 06 Mar 2022 18:15:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bBSm7yrp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233979AbiCFRwK (ORCPT + 99 others); Sun, 6 Mar 2022 12:52:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233970AbiCFRwG (ORCPT ); Sun, 6 Mar 2022 12:52:06 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A4DD3E5F8; Sun, 6 Mar 2022 09:51:14 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id q17so16993050edd.4; Sun, 06 Mar 2022 09:51:14 -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=9KJD2l59oR//tzv+KJB1jDWKlj1X2HYA5Vg/4RaHEkw=; b=bBSm7yrpuQf8NvR6Jd/pLFdEMSIO7nfqIM/HE+oSKBSzDjP8vaLy/jZMNJO0bjaSIj 9SOY9dwJ6PpmVGaav7JdR7rHAOQR0YkkZtMUtdpL5JgfSYQ2jwIagkClD9qWEPpIfaSz BZCjY3e3bY/5lp0AzacTV1aDCfQv0gigptseu48FWFW4wwk4htsM2KXZFle29LzS1/pS Vo/qCx27Xp5s0SqrWZrUUHLXedIE12dPb8OvwR7rA/eNiB1dwkjeo4+2gsWn001EUK5p BiAAFXh2FyjJb0cEb/ClAc6En4lszQQlsz3QqHLomEJQwAYg0TnEqajspa82TKgJ6/xd ugKw== 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=9KJD2l59oR//tzv+KJB1jDWKlj1X2HYA5Vg/4RaHEkw=; b=2fnpA2oaUJgrghAxmfH1fepj0PJ0aJ3dn1qpRjPaRV8WhboizXZ6OpWtcJEffEKZgQ 70HxWC11WDEo05tpOhGJl9/QSGI34i6Su4jMVOO+G1T2BkbCwGpHtRfA3d/poqb2IjYZ 90bzSIKfQd6+0ZxvlZ+ctT6Ym+79Zyh6lD8RWvChHrAcaPRA6fAsAaLmIFoK4cTMUnkl KvS3k9HORAfH2gNtj8EYBfhQUd4MMOffdUDLKZ6+8usgth4bNQJrRPcDqISVBvyZKFfY PLOE+ortLgG9V5tBFIymEsWl9v8ogGrm83RZLqeO21P48HKBDno8xX6p8sM81XP3r1ux SX5A== X-Gm-Message-State: AOAM533RU8lxF9aD6FFkFCpM1OQHtDtPZS7fG1tHDXeEPzjNi8DYUCg0 W3gWuKOW9n12FANPQdvRqjw= X-Received: by 2002:aa7:c551:0:b0:415:a2d0:71a6 with SMTP id s17-20020aa7c551000000b00415a2d071a6mr7615805edr.143.1646589073156; Sun, 06 Mar 2022 09:51:13 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id 20-20020a17090601d400b006caff964e30sm4052606ejj.19.2022.03.06.09.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:12 -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 03/26] usb: gadget: udc: atmel: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:11 +0100 Message-Id: <20220306175034.3084609-4-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220306175034.3084609-1-jakobkoschel@gmail.com> References: <20220306175034.3084609-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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/atmel_usba_udc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index 2b893bceea45..8e393e14f137 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c @@ -860,7 +860,8 @@ static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct usba_ep *ep = to_usba_ep(_ep); struct usba_udc *udc = ep->udc; - struct usba_request *req; + struct usba_request *req = NULL; + struct usba_request *tmp; unsigned long flags; u32 status; @@ -869,12 +870,14 @@ static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&udc->lock, flags); - list_for_each_entry(req, &ep->queue, queue) { - if (&req->req == _req) + list_for_each_entry(tmp, &ep->queue, queue) { + if (&tmp->req == _req) { + req = tmp; break; + } } - if (&req->req != _req) { + if (!req) { spin_unlock_irqrestore(&udc->lock, flags); return -EINVAL; } -- 2.25.1