Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3480614pxp; Tue, 8 Mar 2022 15:32:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwW0uNaHGz0Yr98NAV/oIEUIYqj0OlvEyLfu0O+i4kvUMrTVgDY6o/7usi+/1dFt8tGzDAO X-Received: by 2002:a63:9d48:0:b0:378:c359:fcbf with SMTP id i69-20020a639d48000000b00378c359fcbfmr15962727pgd.371.1646782372445; Tue, 08 Mar 2022 15:32:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646782372; cv=none; d=google.com; s=arc-20160816; b=mpIVNIOIBCIaVTp1L+2pw6xugJ140o2xMGEfcRNhPBhWg0VI4vGZuT75pPlv5gTJYC 2L5EeswXtbWN+bs377OfKJxUMOX0E/tnUggYjsSNvwllT6+YQrycFvvamv41DyQAWOjH FAOM5JMkZWWYzfJzMKrhZ6beKmiRJd4aDBO3i4NP92ecvjZrkxH0KbnGksQuC+fw0v+1 38AOozgtGOsmoLdyHvAr5XUh2VOmw7nliYpdqDWbWeEy6uWnogRzpBmPdHCmSZd4UYlh xNuENm8CWYKbUM5F/sjEtHmEG71IOPoe8yTCYY3m4wui+fj5tA01QX+RPZ9cCQsB5v3+ 5T+A== 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=DV/4uUkufHdigictOlTI0wPqj6AP/gAmirkywlppX9w=; b=u3bTyo92VCFoj2jF7skL4iSV6PqPvuJpabtq765b44h/lkMNIiKFhAOzi2y9LVRl4P BgdaARXGcRWam62s2R8zM1ZUTwkRTRCPzRHP/McJ44+y0LZNm8e+C2EVpL/IpHq8cldC IoItjVthNT15x7iIaGFmgbGIsNuBJmxVbtEXSwp7u+kkJEDPaoleoImTi0ZNh9O8JF26 daPTNa9ozJB4YLdzqiAFzMn5kG6EeykMVxM2wdcoaVPgumH+6tw/STc4iTlXLe1vqwft 1nGfqwfgZFiO5n7W3erwfCfqhu6VYIGRN22fN1yU8EA0hj2xtnYgamUSxoiPoL5Dc0ix Aj/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=R8ehEfpB; 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 b20-20020a63eb54000000b0036c5df3c5b3si241955pgk.1.2022.03.08.15.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 15:32:52 -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=R8ehEfpB; 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 E10EAA9A5C; Tue, 8 Mar 2022 15:21:01 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349017AbiCHRUt (ORCPT + 99 others); Tue, 8 Mar 2022 12:20:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348903AbiCHRU0 (ORCPT ); Tue, 8 Mar 2022 12:20:26 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D18E53720; Tue, 8 Mar 2022 09:19:14 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id qa43so40691594ejc.12; Tue, 08 Mar 2022 09:19: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=DV/4uUkufHdigictOlTI0wPqj6AP/gAmirkywlppX9w=; b=R8ehEfpBbpb8D/RDxqYFEbDZpSJlJ34xGqApi+5PiMot+aaln0rnNVyyMpwDKc35HS xLKLKMqfhb36/qmIqHSpicU2bVGOtUuf8fdi0XjoRHfL+fHQVyf153yQYzXwt2pE0bk3 1CoXoiN/SlIYYSLqZT7rkgVxV9Xx0IW+63M94wYfmr+6wYaBO9UgZxBbyju6tOv6WLcG SEaQC2HCFUeyPe3r2xTtcAnF+ISDQskzF0TT8Ur8xwScacndqA3uO3MfRm5Gd3Jp5fAV BO5zTlXswnx+0NrAKlVIRfsQd/7+Z0zJFfw+FrRSkpLSeZo16/MRgakrERc3wHvI6dvQ 8j2Q== 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=DV/4uUkufHdigictOlTI0wPqj6AP/gAmirkywlppX9w=; b=XG/ek/XxwHSbX/7eui8PPzVDY6vMRC77BWT4vNvEzrZwuXaQ7AupQtvmNmr1usqzdz lwvQJS3MjMdZQVivVtmsSss+Mqb1p4OomfbUGoU6tnG8EbpiFHO5tkMtszVJ3blWQjWh HnDj8ERCxWSzvRJWslQddhnJiarRB8fgX0KwgSBpffFna4eQXM8/bX4YXHY+6UFjN+3N TMZgcTz0zVd+RT7S2Ytym0zoN8vl+TFg2m7Hxdb6wZoNVzXXKI4G9NIEmc28jKIl3RNW M0RGvxIODB7AoCMES+bhe2W6H99xaisqUGoM/VvFCeeYrt42piceolOPUJbIG4INKX34 sFtg== X-Gm-Message-State: AOAM533Vw3huapdIM0O2IgAnRs0Zei95TyHig0r4ykMrLqYQmOgyGR5w PTZsBO6Bzp/epTJnF/VR8C3gNkY+hxgbgXDb X-Received: by 2002:a17:906:1656:b0:6cf:571c:f91d with SMTP id n22-20020a170906165600b006cf571cf91dmr14296621ejd.377.1646759952463; Tue, 08 Mar 2022 09:19:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 06/26] usb: gadget: goku_udc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:58 +0100 Message-Id: <20220308171818.384491-7-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/goku_udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/goku_udc.c b/drivers/usb/gadget/udc/goku_udc.c index 3757a772a55e..bdc56b24b5c9 100644 --- a/drivers/usb/gadget/udc/goku_udc.c +++ b/drivers/usb/gadget/udc/goku_udc.c @@ -809,7 +809,7 @@ static void nuke(struct goku_ep *ep, int status) /* dequeue JUST ONE request */ static int goku_dequeue(struct usb_ep *_ep, struct usb_request *_req) { - struct goku_request *req; + struct goku_request *req = NULL, *iter; struct goku_ep *ep; struct goku_udc *dev; unsigned long flags; @@ -833,11 +833,13 @@ static int goku_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&dev->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 (&dev->lock, flags); return -EINVAL; } -- 2.25.1