From patchwork Sun Mar 6 17:50:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549178 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 7857EC433EF for ; Sun, 6 Mar 2022 17:51:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234067AbiCFRw1 (ORCPT ); Sun, 6 Mar 2022 12:52:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233990AbiCFRwQ (ORCPT ); Sun, 6 Mar 2022 12:52:16 -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 5318D3EAAE; Sun, 6 Mar 2022 09:51:22 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id m21so11492160edc.0; Sun, 06 Mar 2022 09:51:22 -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=mqpR3K55WhurUvs0upPtVeVvH/fxDMxDU4oBZqoDrSM=; b=BHiSKrgrCJz5Wb4TVubZxZToHx7FlG0XHzCR7Es11wbPjMFgtuv04uUQlDHhScminG 829v02U3DERHCcF/0OoNUbvzHDx/l+YYV5pjTwYBemHXbXq0hhnPZi9pUDtWLz7l9e3p BRTC2OzpquQBwHNcWwLyXbDGZJWmZvxh/5TGSVHo326P4I2peSgI/lF/gOQgBAnRW+Wl uQMeEqMcRZIhSbUT518ckse76/gh189zZUpE0bAeEHVDunDWV1qDcWX+LLuDpRYfc12Z ZNj8A+HvWf9OWKn0+g5hNa1m8un5M1PS2mOd/A1XEgL3wMne1owq0IcuMHyVsBCn8z/V mP1g== 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=mqpR3K55WhurUvs0upPtVeVvH/fxDMxDU4oBZqoDrSM=; b=niySl9svHdkR5sTIiZRqOKANsSrJAtANDkEMAI5DM4SpV3iD/auXjhabIFp2B0phCQ wOsAoz7QCzXc66kyzhz5WyJVkAhHaBNM9PsgeiU3Ila1jAHpbD4h9HZm9Fs7GrYeOM0A zD9iHgheSnz9QguwUb4oDB/WUhzFHu+gtC1HWtiZI9NetrJ8QS0qdck1x94Tv98AyOtV dzVI1+DCnMUBkyAwndZpKPj9IKZMdHcltorhzEK7sxHtqzYqUFPuq1zLgudZDXlIEBlj rcxENSSSey1PJiJL1Obgvki/16e4oXSEdMrFCc5mOTBUAdJogadqIhL+s+M52s3N7MP9 hizw== X-Gm-Message-State: AOAM530UCmXuctpOqHJl4Byy8n8GhrXVSlOyTYfw8GtAifObJrJsD7dm W1jZbretEBBHOkV1JdoiQXo= X-Google-Smtp-Source: ABdhPJx4XqYzCobfSNgZhkwMpOzH+EkD5hpK9fzSgOcnlBKU020RKreBP7VVSZG/G1TKAXiqRgZHVg== X-Received: by 2002:a05:6402:2747:b0:415:c252:f5e7 with SMTP id z7-20020a056402274700b00415c252f5e7mr7751608edd.347.1646589080785; Sun, 06 Mar 2022 09:51:20 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:20 -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 09/26] usb: gadget: mv_u3d: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:17 +0100 Message-Id: <20220306175034.3084609-10-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/mv_u3d_core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c index a1057ddfbda3..fd4e9fb661fc 100644 --- a/drivers/usb/gadget/udc/mv_u3d_core.c +++ b/drivers/usb/gadget/udc/mv_u3d_core.c @@ -844,7 +844,7 @@ mv_u3d_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) static int mv_u3d_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct mv_u3d_ep *ep; - struct mv_u3d_req *req; + struct mv_u3d_req *req = NULL, *tmp; struct mv_u3d *u3d; struct mv_u3d_ep_context *ep_context; struct mv_u3d_req *next_req; @@ -861,11 +861,13 @@ static int mv_u3d_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&ep->u3d->lock, flags); /* make sure it's actually 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) { ret = -EINVAL; goto out; }