From patchwork Sun Mar 6 17:50:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549177 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 23537C433EF for ; Sun, 6 Mar 2022 17:51:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230093AbiCFRw2 (ORCPT ); Sun, 6 Mar 2022 12:52:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234042AbiCFRwZ (ORCPT ); Sun, 6 Mar 2022 12:52:25 -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 A548B3E5E4; Sun, 6 Mar 2022 09:51:24 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id f8so16968549edf.10; Sun, 06 Mar 2022 09:51:24 -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=ZKRsJYEvelpvGWMzIOx8XZGCedCQhR6FSA54BP33wTY=; b=qJGJzrzkiFUqEJoWfYe/njqzqLOgY5lnGjKOadmG29WixFkN50bEtC550//3Wi+qZv Zy8b6wWXg1s6tjmfbzLYRWJnYGwtINL9/i4hSPifj4Y0tEr1nMUobCVuZHv+fWH/wGnS Ply0JCictI3AvsC+XP10wfCdcuxTGvOYDk1nbXAiWvtWelhRhvgQ8YxJYRgejkLV+qiq +hVe7w+hep1Yo98BGclN4GjJpNT1DYd8zMXGhv+oUaQe36uTV2tpRd1oDHfvJPeYJwm5 5fSeRxTpHs7OZ6/4vCpbkfePuSW8pnZ85+u8GCXpOp2NMO0LsJ1XoW+Czdr64wGylEWZ 3kig== 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=ZKRsJYEvelpvGWMzIOx8XZGCedCQhR6FSA54BP33wTY=; b=VlrR0dv4JByX7BiidZwqLNNh0dkaRkHzCc9JEBygSSopvehvhmyJlay3sOWI7vRyoA r5CakneOCy/QYHeWwo7+JILE/SGSwgTV5mY1pAvbGzsKiGLYjHnRsqrPrMkxMjl26kFj 0sdCidSDmMlPpzC5G4geiaVmR39ynUXOaANO5CVmz1Zcw1cbd6CYKmU/fb5cnFLP7tmv l/8cA9ZDvXAbrmH1g8uAO5ggSp804iljIxI4y+G6XSKcngEf0qFAUe387P5jSktp15tA F+VFAfm18eAPNwX0pUprtW6fLT6dBBAZNz8aTHFbj3NMQ3JwpIz2RNteIFz8ZO7nUXUA YA4w== X-Gm-Message-State: AOAM5317MXsCA7vob+ICw1eEyV7G1dY9MB30C9mzTRecvSb+gePxKlX3 N+cbGLtvm133IRDTz0i87Xw= X-Google-Smtp-Source: ABdhPJwAIqdYkPNJnghoSQkH4MNJT6av8gVmjbF88ghICJ/jXjQccVIcX7v5VNae20MOBAz9sywbfw== X-Received: by 2002:aa7:cac8:0:b0:410:cc6c:6512 with SMTP id l8-20020aa7cac8000000b00410cc6c6512mr7726113edt.408.1646589083181; Sun, 06 Mar 2022 09:51:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:22 -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 11/26] usb: gadget: net2272: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:19 +0100 Message-Id: <20220306175034.3084609-12-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 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/net2272.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/net2272.c b/drivers/usb/gadget/udc/net2272.c index 7c38057dcb4a..08ce0831c5e0 100644 --- a/drivers/usb/gadget/udc/net2272.c +++ b/drivers/usb/gadget/udc/net2272.c @@ -926,7 +926,7 @@ static int net2272_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct net2272_ep *ep; - struct net2272_request *req; + struct net2272_request *req = NULL, *tmp; unsigned long flags; int stopped; @@ -939,11 +939,13 @@ net2272_dequeue(struct usb_ep *_ep, struct usb_request *_req) ep->stopped = 1; /* make sure it's still queued on this endpoint */ - 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) { ep->stopped = stopped; spin_unlock_irqrestore(&ep->dev->lock, flags); return -EINVAL; @@ -954,7 +956,6 @@ net2272_dequeue(struct usb_ep *_ep, struct usb_request *_req) dev_dbg(ep->dev->dev, "unlink (%s) pio\n", _ep->name); net2272_done(ep, req, -ECONNRESET); } - req = NULL; ep->stopped = stopped; spin_unlock_irqrestore(&ep->dev->lock, flags);