Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3505652pxp; Tue, 8 Mar 2022 16:10:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFxH3ZeZhiYB9fCX03JrK/KsxTI3SUFR6tkwYRCRZ3hznEjIVpLgbClWJf30BJAyA1IDpD X-Received: by 2002:a63:b553:0:b0:374:87b5:fe64 with SMTP id u19-20020a63b553000000b0037487b5fe64mr15816752pgo.591.1646784622743; Tue, 08 Mar 2022 16:10:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646784622; cv=none; d=google.com; s=arc-20160816; b=LF1abnDp54cWaDvfpguj79DASxZvNamu1vWIBhjSdBFBrr8k+u+HRRkMZX91CQcdPU Y71fy+Kb2uqCoJfG5+wGQV00/ESH4XetWIQv3UJLr3yWa5BVJsG8F98uslnk7j2IjFMu ccECmvXADVO6hjjiWe61zxT1v7x5cbkrwPEmNoXRdaguancPmaOSHfRAR4iuxyECBJQC 4sM9SaogxV/ePtq/zmklsek7MKfnDsDees4kRWwgTl5dT5JRFwmCxwtF/gEiE/qCjshM 2/iMKSe6M1EzKD3feJwwVIeNPvCf7TRpL13afsm7ghX6xMbOGveRdRJh0I8r4vmjgDi/ uCjA== 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=CGvztHQgMCmpi1WqEUxl2BM0vU36m9yBUx2ET9/vf+0=; b=0ZYuD1KOAK61exKeiAQCsLu9Nb9tRHAG2FMBp3vf6JWsT1ED3EOSgUh+mYA0/qx/c8 Xww9EBNOHbi1ANMv72ReX1Oiaa1lIiJf6tHRec3IR/9NbKHQosc5zSUFcO7po2NwDwpq GfUQnCmPFRvMNj4OuwqGu5EawHekZS5Tw1C6iofi8+IdVFPPlRa4JAMbphsXxPvNCgpt Iz8gsTzlSKMGyvCUQhBSbs4bJEaFUIAe8eVJa3W+c53oqfeGpImoAFZFmaPC6urxoOxF Khv3ystOT/jGx2Qm7CMMTOISbnxApvraMvQ1S4nAnzn1cuAUTt+dDDPWDlGWDYLLm5kE LFGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YyrXukfM; 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 s16-20020a17090302d000b00151fe42aaacsi391715plk.34.2022.03.08.16.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:10:22 -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=YyrXukfM; 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 8B574B1ABA; Tue, 8 Mar 2022 15:40:14 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349076AbiCHRWB (ORCPT + 99 others); Tue, 8 Mar 2022 12:22:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348994AbiCHRUk (ORCPT ); Tue, 8 Mar 2022 12:20:40 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE3E9541AC; Tue, 8 Mar 2022 09:19:31 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id bg10so40814643ejb.4; Tue, 08 Mar 2022 09:19:31 -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=CGvztHQgMCmpi1WqEUxl2BM0vU36m9yBUx2ET9/vf+0=; b=YyrXukfMZwnEEZrPAwnqcHzxASANGmibqZoi/p2nngxd92F83KKYuhPvflo1n7UjZ/ ce79fBag3W+VLCbRaMz2UfupvxNw6V5dwuRHtgFIAyGBakgm3YNqPDvDnAoL8Mhccamq dsEQWyykl7Ze0+Tgy3DxSjxvraHDf9PzeGMiU+y2yihQWx3vkNtOEjUhI0gqFxnHqcqx 05Y1huktCi5BqrKAiaBtMnVyRKwDkJNtWgFNxGLGFsdLPr8Uy0uFU6cwI9Xd3uI5sRGn CEkqG8+A799Re+i75Xi8rUdTGS2TMSRlANNSmycqyufFEw12xKqCjePBc1akYMKxt55q qESA== 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=CGvztHQgMCmpi1WqEUxl2BM0vU36m9yBUx2ET9/vf+0=; b=gfmrwf0QhuAwSYHtfrmbCOtOAYMnzZhh89tFTmCy8jk3Os0+qeSXi/HsOUeAL0uHX/ 8t5Unynqf98WmzAL02dsaKiETn5e8Zh4Mu2iDvuMdA/dWE1jzJ1KeORK2qDQRNyHTdNy BQ00yUKJwHKcAg2Cx+ys0bxASuAgpGBkcSaQh+ej0aomieC+OCxKfuf0jw7c68bI6ZLx 5EPUvMJkeV+yq1noKAGLv75AnRmQVfYdH6XaxNn+9gjnIlqEA6SpZlMk+uQDDYh840ot kQiuSX4bcMAgAdWp1veOv36C61rs8fu6uPfyqxVSoDzoWvtzN9JusPR2NgTHJqxLQeca YwhA== X-Gm-Message-State: AOAM5306RTTssOTmlUOUbGl7cIVpZk+y+FbmaBj7XFYlFw5NGTDRtGVO 9a8h4Xcip6hLg4gCbE+wMJ8= X-Received: by 2002:a17:906:6a81:b0:6da:d7e5:4fa with SMTP id p1-20020a1709066a8100b006dad7e504famr13910360ejr.223.1646759970436; Tue, 08 Mar 2022 09:19:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:30 -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 19/26] usb: gadget: udc: max3420_udc: remove using list iterator after loop body as a ptr Date: Tue, 8 Mar 2022 18:18:11 +0100 Message-Id: <20220308171818.384491-20-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 does not contain the expected element, the value of 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 list_for_each_entry() loop. In preparation to limiting scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1]. Determining if an element was found is then simply checking if the pointer is != NULL instead of using the potentially bogus pointer. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/max3420_udc.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/usb/gadget/udc/max3420_udc.c b/drivers/usb/gadget/udc/max3420_udc.c index d2a2b20cc1ad..ac8a46bc1057 100644 --- a/drivers/usb/gadget/udc/max3420_udc.c +++ b/drivers/usb/gadget/udc/max3420_udc.c @@ -1044,22 +1044,26 @@ static int max3420_ep_queue(struct usb_ep *_ep, struct usb_request *_req, static int max3420_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { - struct max3420_req *t, *req = to_max3420_req(_req); + struct max3420_req *t = NULL; + struct max3420_req *req = to_max3420_req(_req); + struct max3420_req *iter; struct max3420_ep *ep = to_max3420_ep(_ep); unsigned long flags; spin_lock_irqsave(&ep->lock, flags); /* Pluck the descriptor from queue */ - list_for_each_entry(t, &ep->queue, queue) - if (t == req) { - list_del_init(&req->queue); - break; - } + list_for_each_entry(iter, &ep->queue, queue) { + if (iter != req) + continue; + list_del_init(&req->queue); + t = iter; + break; + } spin_unlock_irqrestore(&ep->lock, flags); - if (t == req) + if (t) max3420_req_done(req, -ECONNRESET); return 0; -- 2.25.1