Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3522447pxp; Tue, 8 Mar 2022 16:33:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBARvHqWXWaWxfvfcddiYruWkRNsspOnW819VtRGfO6hD5txRHkpX6dW85MuraL9m7+CQe X-Received: by 2002:a17:902:bd95:b0:14f:40ab:270e with SMTP id q21-20020a170902bd9500b0014f40ab270emr20049159pls.101.1646786018462; Tue, 08 Mar 2022 16:33:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646786018; cv=none; d=google.com; s=arc-20160816; b=x59k9ipQQGyH63oVXu86lOvXe1x/nhKz/T88jwYlswIcWVxeiwnB9qnZGSaFzrIHmp SHP42eA7kMSUXGf5v35FIpHL1Cg2MNZkW90Mp0EDlSVPhlTozCzcdBeCI6OAgAfsBzDK +k/Y9RxIL0CxCcffYa++pwtEJk43VV1U4pfodI0laljKUCZB5pbuU8NOS4mSadLGW4MA ekLvBdM/NmoKdzX3PC8JOvRcKSVl5s+8YUEzP45T7vv3WHGyLgxXErXhZ9Y7KMBxfuBD MjRD82Jg+XTYe5TH1njFUXndREj9QeDmyrEtivoHLpJ5MpZBtUrqPW8MDSov8Ro+hPm7 6Zrw== 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=xSwIYlrd4/uGvEtywTYOBSlI+/oM9Fdz2FSLOBGr2xA=; b=pvTRlJECDZIIbOktjzCnFIC4yMFBFY3USDNwYv1RooXnX9hIM7HCUr2ygPMeCVImqo XHDnZLVZ+q2ly0+u9VTmQphCV39z1gbj09rfLtmCdHjpjBG1HpQw39Ol0Xf0lgovhZ4H HxmkPQQ/cLyL2uHGLJ0pwCcmFUCFomZifwllN5Jo9sGWQz4iVPVFS0YXxDVZYRxVfhOZ ubDgrOOoLGv/tMPh+lAd2kn/JcYxODug/teil2veywbb+Cr7w8+2kCyndpUpPLnltI1V Nh/C0q3NnrlS/UJvqydwq/Q4X3KIBDnXDaa8hYkbcrZCm9NaCLj0SWyd6C+135zHPnYI E5eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f82f42+N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id pc18-20020a17090b3b9200b001bd14e01f88si520821pjb.118.2022.03.08.16.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:33:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=f82f42+N; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 288F0111195; Tue, 8 Mar 2022 15:51:26 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348434AbiCHRVU (ORCPT + 99 others); Tue, 8 Mar 2022 12:21:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348915AbiCHRU2 (ORCPT ); Tue, 8 Mar 2022 12:20:28 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A546C1EAF3; Tue, 8 Mar 2022 09:19:16 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id kt27so40907349ejb.0; Tue, 08 Mar 2022 09:19:16 -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=xSwIYlrd4/uGvEtywTYOBSlI+/oM9Fdz2FSLOBGr2xA=; b=f82f42+N57pRAxK1PdtQfQj4EV2Dzh/MPG09nXy5zlY3XeI8nGy3r/XtVaZj5y814j I5RvcOiX9K4B0XHWrUqgSN5f+YN0AjRt9mlGOh2nm+Bvn1huEJmDo73cUitnPi6JgaAW sC2OR6jfGz7nids6AhjVhKJujGkL9BC+lDe9XfI9vwt4hN7YMuweP3wzPm8+wKsyeVyy 1OMAclsJJ1Tyoai3wW4RO0MI/Pn2aEIcrAkszGcuGuAGDmDu93YRnaTYuS2FLhxklcD5 SW4vUri6GNI2s48km3COIeUf7ysS4UuEdMsGgXnrJZgZagTqAbh0+AwXgRkp9H1+U/5n 7mpg== 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=xSwIYlrd4/uGvEtywTYOBSlI+/oM9Fdz2FSLOBGr2xA=; b=NQDFNgLSCcMFxaty/LqayHgo42WWTPcHV1gsXSrGgVzlCflrgkjrKgaE2cIBEt2c5u Nzuou0QjtNVXry+FOrUvcm8U4fnxZV5UZZ+uX0ZiZakAMNwmiD8cRjkAbW+21DsXRa+Z UtnXCvn8QV+XhpG16Mz2CxM/qzemzKUpcEr21QoX+EGW62p20vATTlGNbkcbXpN7DyFl zsrOH3AfA5oVgpr+y/x/xZB1w/4g0zFd6aFNfrtUdWzr6g2pcrfP3hNW0e2Hbe7xywUd JssFP9hmVKLh8YJWAL/O44WkHPuoX/YRhRK3KGEuRHcYfjE/q2QiPXQHcda7qaQ/Mu84 a85w== X-Gm-Message-State: AOAM533Qhs954xJxQwgy/w3dRVPI8KtA9kpOfz3PjKcOFo1uEKPQ6tYk zUP80hZ5yWea0Nw2jR8hsR4= X-Received: by 2002:a17:906:c10b:b0:6da:a190:edb0 with SMTP id do11-20020a170906c10b00b006daa190edb0mr13847639ejc.512.1646759953551; Tue, 08 Mar 2022 09:19:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:13 -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 07/26] usb: gadget: udc: gr_udc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:59 +0100 Message-Id: <20220308171818.384491-8-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/gr_udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c index 4b35739d3695..22096f8505de 100644 --- a/drivers/usb/gadget/udc/gr_udc.c +++ b/drivers/usb/gadget/udc/gr_udc.c @@ -1690,7 +1690,7 @@ static int gr_queue_ext(struct usb_ep *_ep, struct usb_request *_req, /* Dequeue JUST ONE request */ static int gr_dequeue(struct usb_ep *_ep, struct usb_request *_req) { - struct gr_request *req; + struct gr_request *req = NULL, *iter; struct gr_ep *ep; struct gr_udc *dev; int ret = 0; @@ -1710,11 +1710,13 @@ static int gr_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) { ret = -EINVAL; goto out; } -- 2.25.1