Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3557604pxp; Tue, 8 Mar 2022 17:24:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwV6khyLIqMohiwWa7CUYlYuMQCmeSyR9bOhKT9ktSmdHxG4TDTmwti31oGlPTU5DI9pwdy X-Received: by 2002:a63:2d0:0:b0:380:b9e3:fa1b with SMTP id 199-20020a6302d0000000b00380b9e3fa1bmr167680pgc.43.1646789054419; Tue, 08 Mar 2022 17:24:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646789054; cv=none; d=google.com; s=arc-20160816; b=uGNmtWck27GXu5LJZrcVExmxozcKTLrZ05L9qgLlP8GIodq2SCrYHvxoFSMDwcnJDr CumXSauxGa7oSFzVse1u+PeCOhxyv2grqOcPxeeizrCgcNKssBczfMmK9D4QnmfOkpym pELMXt8518ji1wnlhCkLTcxXz9BIzR0ZT3+fN1Wam7x2wbvkfn65plAhnxgKNx7kG/2y 6i6EFSvgGGaoxCogJXT+M1HquiShNLSF+Tp7HW2lQXfnWS2cU7upkqc+k3dq+lw/XWE1 FMM5+sGEMxePvI4tT+WLZqXnRzXqzN6vZo+Q2EOzezK4qXE2a/tp/9DOS9ZmaQ92IYKG qqXQ== 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=FiQ4puCFE77hcY5XsHWeEmKJVjDUyRyfQhSidRFLY4Y=; b=xJ4TEMQdclBFo51/anh+bq89WKMqoHPsDaP63rmDmCiv2boFPuG3QiPWhEPXlysZ8B lbvXIorNcbLCodLIzVUS0b8DeudtB663+dHqPIvlYW2Leg1uNdm9789hbiD4AKGZlySE HZ8aFA6331h+qashuzntVM5uUG44VDRXqkEP3UO7dXKpz1ZeNuCDfWrYZkaPvY3TlSBu xnuzPN3x+4SsHHbHDZAM8kXjciAoywnbVl1oHXTCPXG/YokuxoxkR/DEgaWAP1QaMchS Oqi7g+N2+9d99m2FswtAt4B96rJXDnVYNwjZsgIBT3qphetZnz6P2EzezGxgGYQjXQqR 9kFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l0epHchF; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id j70-20020a638049000000b00380ac8c42c8si432814pgd.809.2022.03.08.17.24.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 17:24:14 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=l0epHchF; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7283197B7D; Tue, 8 Mar 2022 16:15:30 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349046AbiCHRU6 (ORCPT + 99 others); Tue, 8 Mar 2022 12:20:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348947AbiCHRUU (ORCPT ); Tue, 8 Mar 2022 12:20:20 -0500 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A019C53B46; Tue, 8 Mar 2022 09:19:10 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id c20so6975882edr.8; Tue, 08 Mar 2022 09:19:10 -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=FiQ4puCFE77hcY5XsHWeEmKJVjDUyRyfQhSidRFLY4Y=; b=l0epHchFHciZJxsva8RSY8pNQ3WDGf/eZd1iy9Mq/XLOv+t96W3/QtX9vtGfgB/dCB W6w+V023vcKsjpn3UUO3VAIHmSgwpNv1jD9KR7BYD4H3KvRijf8TdUUrkFCxE8tkxKfD Cwd/q8dKe/y2W3MESJbRiaKly6OMLZsCDHV6i1KoUgEnuicD9SGghZFPZpS3QaNCgTpH eKQkvJyjAp+x4y+XrAPXRrooT94BRIM8gpw2W/CZtE/K8poXB2+5RWW5SHGPpV41DZAT hZZOxOywa4ggoLqriGpFYAIRvIAIVrPl9TzToEDd6c9EYGJOnjHj2m3vwhZTU1qdlbLp UgWw== 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=FiQ4puCFE77hcY5XsHWeEmKJVjDUyRyfQhSidRFLY4Y=; b=o7zmSAehNbj5sj5rUqsJHO7P/KwkAH6mcMnJaYpq1HTWytstboIYqwl/PoCj9C1DCX +lvoAc7ipb5H33XVvVbEQinecLNrod/fdgp+1U8/rwcIu71WYXTlNZSiZppJGSjVJ2Rn 0NlHnNjcou/omODk21wjkztnMCLZN89FmD9OnoOB39t4CdDewye3I5rzexyscDTRstfY HkMagGcL+w8tuNDtNU7KwHHxZqHsL3OoXjo1FbfdxORVh1HanXpbPImGgMqzSUGf7LMz PACGbmMC00rqLdwUb7QlT2pn+Pi9lZ4p88+H4ZAKOJMKqfqEZzE0zg8oVJ0ItMkpRDo/ oMng== X-Gm-Message-State: AOAM532mzrq+v8K3BwXfXIxw2soLeUGYJkcmP0ILhVkETrnYl1nqETdo R2HwtFXNYYwMNPK98F3ZAG4= X-Received: by 2002:a05:6402:37a:b0:415:9501:e112 with SMTP id s26-20020a056402037a00b004159501e112mr17432359edw.402.1646759949139; Tue, 08 Mar 2022 09:19:09 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:08 -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 03/26] usb: gadget: udc: atmel: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:55 +0100 Message-Id: <20220308171818.384491-4-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index 2b893bceea45..ae2bfbac603e 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 *iter; 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) - 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(&udc->lock, flags); return -EINVAL; } -- 2.25.1