From patchwork Tue Mar 8 17:18:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549650 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 A0E6DC433EF for ; Tue, 8 Mar 2022 17:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349024AbiCHRUu (ORCPT ); Tue, 8 Mar 2022 12:20:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348966AbiCHRU3 (ORCPT ); Tue, 8 Mar 2022 12:20:29 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A5CD5372D; Tue, 8 Mar 2022 09:19:19 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id x5so25369090edd.11; Tue, 08 Mar 2022 09:19:19 -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=N8sypLoqqUrLokDZ1BzWM/CJRguZ5x0Xpk1JVIhPD+M=; b=pzSWzeP0NZJI7823NFDxQfOeimyrLNPWnRxdQ0Q2zZpkwOJ2LxfVRP5kT/iVQkXkYP dJC4nMDHXqSVGosla1Mygiwl7sLIVTX+tGGNMRgeaGdvxUb4tOps1vVtEdMn+yGZ7YKQ jDCm8s401NwC61bRAOzIUso1sQKSPcOxyWze258ctr5oCmD0PKM4gxwvCVD+k2fs7fmQ m//ugy4ckRAT3cxsT4QFESj5lnwUzcFTm3YUaaFdd2sFxPjh+saGaDRbsfCnslazbefa 5PZa+CtTM7BwjhCTfWHlwIZKTaBay2BrcgsioorxDbFOPWApXR9ErdQukCMbUsrY7lA/ 3RKQ== 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=N8sypLoqqUrLokDZ1BzWM/CJRguZ5x0Xpk1JVIhPD+M=; b=MiZeOifNf0lUCoJnAZXwJgNA5SexvFYargHLkd2mPwItTHc3PPfCVOqGZz4cRwK/M+ fGviOGxFGDf+VKPII6sniJxZe9LNtkkYMX2xSzT6qEcDg/2Q6SDqCUbCJuQNND32F38D ROvlBwj9aao0MnSz8HFWAs55XgE6BIU8oZwOgaqsiespKeKGQ5CsrT7KIIoVqOunuSko bGSkRkppZ9vWCDovOll9xVuMnA0mREJIO8t7aHAo5NhZBBGuTGEyKi5nw3jhfHYE1Mae bCLxWZ0Iq16WetND4i3Re6WHVas+/KQKGyQ7MKbV5VQldD8kbqEu3XuF+MhZOxDYgnNl VPgQ== X-Gm-Message-State: AOAM531AKtN9OV7iRJ2NwfdkKkZJDSzLSaEY8kAdBR0eADUuR+NPKxF4 qY3eAopSZzTtgNRVxNt43Hc= X-Google-Smtp-Source: ABdhPJya6Jg7Xf6nO/bt1TDUmz8xwHdfXlH0dr4/PEoFUpTykApNyQsj86pewvESMbIv/HizWDLnHg== X-Received: by 2002:a05:6402:d0d:b0:416:1d69:f23b with SMTP id eb13-20020a0564020d0d00b004161d69f23bmr17205986edb.141.1646759957318; Tue, 08 Mar 2022 09:19:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:16 -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 10/26] usb: gadget: udc: mv_udc_core: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:02 +0100 Message-Id: <20220308171818.384491-11-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 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/mv_udc_core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c index b6d34dda028b..fdb17d86cd65 100644 --- a/drivers/usb/gadget/udc/mv_udc_core.c +++ b/drivers/usb/gadget/udc/mv_udc_core.c @@ -771,7 +771,7 @@ static void mv_prime_ep(struct mv_ep *ep, struct mv_req *req) static int mv_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct mv_ep *ep = container_of(_ep, struct mv_ep, ep); - struct mv_req *req; + struct mv_req *req = NULL, *iter; struct mv_udc *udc = ep->udc; unsigned long flags; int stopped, ret = 0; @@ -793,11 +793,13 @@ static int mv_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]); /* 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; }