From patchwork Sun Mar 6 17:50:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549182 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 14F83C433FE for ; Sun, 6 Mar 2022 17:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233961AbiCFRwF (ORCPT ); Sun, 6 Mar 2022 12:52:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233831AbiCFRwE (ORCPT ); Sun, 6 Mar 2022 12:52:04 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35AA13E5DD; Sun, 6 Mar 2022 09:51:12 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id p15so27458436ejc.7; Sun, 06 Mar 2022 09:51:12 -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=MFt2C4v3MHiA6cRFvbwFucUFojonhWM9CACowSfppes=; b=Tolycnv7VYddPSTnHUPVc8T2MLtAr6i1eIjLjhBH86eZUoumoTFWROly+HHb06LqB3 ugHsQtipGLBEGBGc/SOLNog12BqLN5Xdd17r2TO4VR34UBns31kYHGmNJBZ2zepTxuVE 7GU/RjLNn0/fIaG2hbIYjgjMPaHF83ma18PD/op0cDq8lEamu0dF8ae3CB4mW5X08BFk fqE5yfu6Q167r6L4wJcOwCsX4MfAxduSA+q4mQX6QrKXJFcX2yB3CvGf70ueBRGHSxcb Or3DPvp3Ic8PrVu9Af3nPM8uUV+L3uVGasnhL2egxvGCVtSz3bLYr411/OnZJVO87aUc 1JHA== 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=MFt2C4v3MHiA6cRFvbwFucUFojonhWM9CACowSfppes=; b=lBt21sUzMMzy7UQrlCx+0edgmWAVE8ITCqvXe9SXlg8lNHK8IDRFULffVZFTUXdG6l 4xqxQmlgXCn9cQH81gS6cQ4Cx2zeV7aG4UhjMCIbvpyyKfb/757y4i392nh3mOYANaff r4aIdZn04hzsZwNupBLbcS+PeqS6XEFZXd7mER61wMUGdgChcBiNypoMiA+CaARd1vrh rFGP+pL/H333oom35cmAaDu+UIvgLJsBHTars3R1TKAFAUqVzxOPoHa6aM3hYfJlwjSU PyKe4A+h3ZLFOJqj6pwaNdgMEX4fSa063iJsBgkLhuIDZxAFOfu7gUTONGy5LizfBKOp JEAw== X-Gm-Message-State: AOAM532SEbHqVf3c3tGn0OrOtgpTJTPMnsKOuhSZfHtspK1TXzXTM05P 121tqjr5nZD+elhz5p0gD4I= X-Google-Smtp-Source: ABdhPJxcBDS2fKAC3UP2mJtbSlN6nfaiW3fyJgPpLmVwl8GN6KhfNQ55qpfpsXcMqKt2QBcWUp3vQQ== X-Received: by 2002:a17:906:c053:b0:6b5:fde8:af2 with SMTP id bm19-20020a170906c05300b006b5fde80af2mr6500304ejb.642.1646589070687; Sun, 06 Mar 2022 09:51:10 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:10 -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 01/26] usb: gadget: fsl: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:09 +0100 Message-Id: <20220306175034.3084609-2-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/fsl_qe_udc.c | 11 +++++++---- drivers/usb/gadget/udc/fsl_udc_core.c | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/udc/fsl_qe_udc.c b/drivers/usb/gadget/udc/fsl_qe_udc.c index 15db7a3868fe..3979a2825e3c 100644 --- a/drivers/usb/gadget/udc/fsl_qe_udc.c +++ b/drivers/usb/gadget/udc/fsl_qe_udc.c @@ -1776,7 +1776,8 @@ static int qe_ep_queue(struct usb_ep *_ep, struct usb_request *_req, static int qe_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct qe_ep *ep = container_of(_ep, struct qe_ep, ep); - struct qe_req *req; + struct qe_req *req = NULL; + struct qe_req *tmp; unsigned long flags; if (!_ep || !_req) @@ -1785,12 +1786,14 @@ static int qe_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&ep->udc->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) { spin_unlock_irqrestore(&ep->udc->lock, flags); return -EINVAL; } diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c b/drivers/usb/gadget/udc/fsl_udc_core.c index 29fcb9b461d7..23d670fae12c 100644 --- a/drivers/usb/gadget/udc/fsl_udc_core.c +++ b/drivers/usb/gadget/udc/fsl_udc_core.c @@ -918,7 +918,8 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct fsl_ep *ep = container_of(_ep, struct fsl_ep, ep); - struct fsl_req *req; + struct fsl_req *req = NULL; + struct fsl_req *tmp; unsigned long flags; int ep_num, stopped, ret = 0; u32 epctrl; @@ -940,11 +941,13 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]); /* 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; } From patchwork Sun Mar 6 17:50:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548843 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 E887BC433F5 for ; Sun, 6 Mar 2022 17:51:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233972AbiCFRwH (ORCPT ); Sun, 6 Mar 2022 12:52:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233964AbiCFRwG (ORCPT ); Sun, 6 Mar 2022 12:52:06 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E96C3E5DD; Sun, 6 Mar 2022 09:51:13 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id x5so16955578edd.11; Sun, 06 Mar 2022 09:51:13 -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=utzkgFEY4qR62mpmuTqoKbVS/KHHWuTcrin4SG2ItLk=; b=dU8nCpPNeMYUssBxZy7S6AHFLVFKJLYOyJzP1aq7xOE0VDG28AJJQ4JnLwQlNXqMm5 0qqGBMSzlynThyYX6cLA2RUxJlqqAuvN4A7h5IHBf94FQzjMPnFY4SExqC+ybFGf0hXu jvqhC7ayw1jDIC8E7/KUazqmDvKZ9vxQft3xCKFz71dq9+OxJDaUHAM/uMiH5S+mArgP HiozY5edfBGQuDs0YA3hGbuJau3xKxv3V2pJ8qIFss8Ri4cTc7Nc80bKKEQSjy84bCae 8/ZjkTAA5zedjZVlMwVx0GOWBPcZycTn9XrrZnoTBN49WMk8MYd9jcerjP9+dG7L80xb OrUQ== 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=utzkgFEY4qR62mpmuTqoKbVS/KHHWuTcrin4SG2ItLk=; b=Pt21ktcwjkMUsR9opUw2S+DdnJ2xJc9+y/2lSEwG4Ef0Nd4ABQJGhtpEt3YWv/VZJj cC/1BTtkSZxQBSRJFlk7PxwW+ZaVZ3P+MIOnIFsG7u/mra7kS6kz/+usy5avUephkty7 H2lfQ6ao3QEjYKWOgMQW7MtwfH1EpK/tjIUHJagoFICHqzpZHLN8aByDh4DZsXFxFWLU Uu8ljUaWW51apP3ESwrYm6vLARkvs7Ckl1tL/6nD2qDKGQ+RcA0MVYn3H9R/QwpZCiBV E3Og1JHi5YMgcde4n5MjgcP1j52lk5isu06FD1msKEUbe6ZFFwX38OzzHIzZAtRNjpU8 7BYA== X-Gm-Message-State: AOAM531TypMy2YwVa//crvLuVpmmdrOumhPRVWip/lzIMVK+23vIFhYx HZyPefUq2fevKxS3OvEk8fVRDUb9kOO8s1ch X-Google-Smtp-Source: ABdhPJyBvRe3Tm9Y4tGFrpfzQTpJdOxekhWPpbWfaYPc0+SljeyEqAFJc0JOS0vMfYEm10QkLA/0Eg== X-Received: by 2002:a50:8708:0:b0:416:765:c4c4 with SMTP id i8-20020a508708000000b004160765c4c4mr7513658edb.245.1646589071949; Sun, 06 Mar 2022 09:51:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:11 -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 02/26] usb: gadget: bdc: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:10 +0100 Message-Id: <20220306175034.3084609-3-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/bdc/bdc_ep.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c b/drivers/usb/gadget/udc/bdc/bdc_ep.c index 8e2f20b12519..829e96791d0a 100644 --- a/drivers/usb/gadget/udc/bdc/bdc_ep.c +++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c @@ -1757,6 +1757,7 @@ static int bdc_gadget_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct bdc_req *req; + struct bdc_req *tmp; unsigned long flags; struct bdc_ep *ep; struct bdc *bdc; @@ -1771,12 +1772,16 @@ static int bdc_gadget_ep_dequeue(struct usb_ep *_ep, dev_dbg(bdc->dev, "%s ep:%s req:%p\n", __func__, ep->name, req); bdc_dbg_bd_list(bdc, ep); spin_lock_irqsave(&bdc->lock, flags); + + req = NULL; /* make sure it's still queued on this endpoint */ - list_for_each_entry(req, &ep->queue, queue) { - if (&req->usb_req == _req) + list_for_each_entry(tmp, &ep->queue, queue) { + if (&tmp->usb_req == _req) { + req = tmp; break; + } } - if (&req->usb_req != _req) { + if (!req) { spin_unlock_irqrestore(&bdc->lock, flags); dev_err(bdc->dev, "usb_req !=req n"); return -EINVAL; From patchwork Sun Mar 6 17:50:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549181 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 94F6EC433F5 for ; Sun, 6 Mar 2022 17:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233976AbiCFRwI (ORCPT ); Sun, 6 Mar 2022 12:52:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233970AbiCFRwG (ORCPT ); Sun, 6 Mar 2022 12:52:06 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A4DD3E5F8; Sun, 6 Mar 2022 09:51:14 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id q17so16993050edd.4; Sun, 06 Mar 2022 09:51:14 -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=9KJD2l59oR//tzv+KJB1jDWKlj1X2HYA5Vg/4RaHEkw=; b=bBSm7yrpuQf8NvR6Jd/pLFdEMSIO7nfqIM/HE+oSKBSzDjP8vaLy/jZMNJO0bjaSIj 9SOY9dwJ6PpmVGaav7JdR7rHAOQR0YkkZtMUtdpL5JgfSYQ2jwIagkClD9qWEPpIfaSz BZCjY3e3bY/5lp0AzacTV1aDCfQv0gigptseu48FWFW4wwk4htsM2KXZFle29LzS1/pS Vo/qCx27Xp5s0SqrWZrUUHLXedIE12dPb8OvwR7rA/eNiB1dwkjeo4+2gsWn001EUK5p BiAAFXh2FyjJb0cEb/ClAc6En4lszQQlsz3QqHLomEJQwAYg0TnEqajspa82TKgJ6/xd ugKw== 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=9KJD2l59oR//tzv+KJB1jDWKlj1X2HYA5Vg/4RaHEkw=; b=2fnpA2oaUJgrghAxmfH1fepj0PJ0aJ3dn1qpRjPaRV8WhboizXZ6OpWtcJEffEKZgQ 70HxWC11WDEo05tpOhGJl9/QSGI34i6Su4jMVOO+G1T2BkbCwGpHtRfA3d/poqb2IjYZ 90bzSIKfQd6+0ZxvlZ+ctT6Ym+79Zyh6lD8RWvChHrAcaPRA6fAsAaLmIFoK4cTMUnkl KvS3k9HORAfH2gNtj8EYBfhQUd4MMOffdUDLKZ6+8usgth4bNQJrRPcDqISVBvyZKFfY PLOE+ortLgG9V5tBFIymEsWl9v8ogGrm83RZLqeO21P48HKBDno8xX6p8sM81XP3r1ux SX5A== X-Gm-Message-State: AOAM533RU8lxF9aD6FFkFCpM1OQHtDtPZS7fG1tHDXeEPzjNi8DYUCg0 W3gWuKOW9n12FANPQdvRqjw= X-Google-Smtp-Source: ABdhPJzEwgTN+VhtiuAhGsjzB8Kjx0sKauMjB7e9IheDHqWCwiWA3p97ekn80zm0aTMLnAInrootsQ== X-Received: by 2002:aa7:c551:0:b0:415:a2d0:71a6 with SMTP id s17-20020aa7c551000000b00415a2d071a6mr7615805edr.143.1646589073156; Sun, 06 Mar 2022 09:51:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:12 -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 03/26] usb: gadget: udc: atmel: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:11 +0100 Message-Id: <20220306175034.3084609-4-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/atmel_usba_udc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index 2b893bceea45..8e393e14f137 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c @@ -860,7 +860,8 @@ static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct usba_ep *ep = to_usba_ep(_ep); struct usba_udc *udc = ep->udc; - struct usba_request *req; + struct usba_request *req = NULL; + struct usba_request *tmp; unsigned long flags; u32 status; @@ -869,12 +870,14 @@ static int usba_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&udc->lock, flags); - 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) { spin_unlock_irqrestore(&udc->lock, flags); return -EINVAL; } From patchwork Sun Mar 6 17:50:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548842 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 79F66C433F5 for ; Sun, 6 Mar 2022 17:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233987AbiCFRwL (ORCPT ); Sun, 6 Mar 2022 12:52:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232643AbiCFRwI (ORCPT ); Sun, 6 Mar 2022 12:52:08 -0500 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 024B93E5F8; Sun, 6 Mar 2022 09:51:15 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id s1so16932675edd.13; Sun, 06 Mar 2022 09:51:15 -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=f5+1KVl6xG8fB1kYFIuwRtTBn1Y4V5ASbbZ+diDolcU=; b=ge0Bt7NZK1tqAmaS2XgbtreVorDpKfDnbik/79y+hzdYQPyOEQN0kNHebGiQ/Mmv7C 6GLlb/rz9tsv8K0LUXJrDm86ShdR2hWJIq2vK6epM8d0hgYCw+ijpOYEhuBzGyZ2p+xy NltSV4qWtiPYvxilTjeTqq/aluaaxdcASdQX+qoZciOj56uXEyN8ft/qKMMUkraYrvq1 TffadnFKU0tI3X6U8hJvIPZYMhFwfWTGtMpNklzpmRLg/atu+49rIfOWC4rtGlQcjKGE 60bk8ZP8xjj5ofC6WtjHDZ0PHL/YIyWGtbInNtb1TfdrttpHn7imcV0+PSfRutlAe0BU gSpw== 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=f5+1KVl6xG8fB1kYFIuwRtTBn1Y4V5ASbbZ+diDolcU=; b=GB6zh1mf/o6zStYN5s2+FnOvni7rAm8yjTlDnQcpF4TseZSd328m4rOsnH8YkL0Mrm xCWtrBjrfl37utoUN0a2+D9C/vCHFAxbhFRVJbCbqQ7m4wiQA1B8xON1vPMlKjF0oncU pUZssS/lZU0pX/A5h0VIyPqm1KM8RZJ+QVsttFWjCGzDorSpVktfGyy2+1zbDfD+BYC2 d2Quq4AcccGNe5PRhth9QIg2dcd2H6cqVEZOd6p9soz28uTeGtQU8w7q6tXWM+r4TAGc x1LORpbShzIPJ20LvDEHNa4hNweCPWQc7pktS7FGtIJSsIch/yL/GH1JEmkhoeMllnJt C9xQ== X-Gm-Message-State: AOAM533qieX4ftW/AqA4AubgZ/+Z47XNd/S6svCZGJtYNlQZC0rn4K9j 5s2OFLQV5f8O0Mc2/uIp5pM= X-Google-Smtp-Source: ABdhPJwsKmgLwmn+m+ySNLhZ6J2/wCVO+QnZ592jatK3OtiS16z+klQADQuM2R4Xb7xzn5cwihOB3A== X-Received: by 2002:a05:6402:1c02:b0:415:f555:38ba with SMTP id ck2-20020a0564021c0200b00415f55538bamr7566215edb.357.1646589074454; Sun, 06 Mar 2022 09:51:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:14 -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 04/26] usb: gadget: udc: pxa25x: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:12 +0100 Message-Id: <20220306175034.3084609-5-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/pxa25x_udc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/pxa25x_udc.c b/drivers/usb/gadget/udc/pxa25x_udc.c index b38747fd3bb0..889ea52bbe0a 100644 --- a/drivers/usb/gadget/udc/pxa25x_udc.c +++ b/drivers/usb/gadget/udc/pxa25x_udc.c @@ -966,7 +966,8 @@ static void nuke(struct pxa25x_ep *ep, int status) static int pxa25x_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct pxa25x_ep *ep; - struct pxa25x_request *req; + struct pxa25x_request *req = NULL; + struct pxa25x_request *tmp; unsigned long flags; ep = container_of(_ep, struct pxa25x_ep, ep); @@ -976,11 +977,13 @@ static int pxa25x_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) local_irq_save(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) { local_irq_restore(flags); return -EINVAL; } From patchwork Sun Mar 6 17:50:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549180 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 AF874C433F5 for ; Sun, 6 Mar 2022 17:51:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233995AbiCFRwQ (ORCPT ); Sun, 6 Mar 2022 12:52:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233982AbiCFRwJ (ORCPT ); Sun, 6 Mar 2022 12:52:09 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FB033EAB9; Sun, 6 Mar 2022 09:51:17 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id hw13so27354035ejc.9; Sun, 06 Mar 2022 09:51:17 -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=LPCpnczupXrz9W1UzaA2UvvdLj0jWSqGpTMR1qrezRc=; b=j0EMQvl8+2JFYZUlgE872rr/CHUfMBvkLmRRjeP8Jd18PjclIYFaz3q0Hk2HglOYSp 3tzyraqyo58yj3TBOuPP+CDiHYWcnSXC8pjo+upKsHSHGR3dBP6YQAac1CYPzpfR/CMY rNN5DyivS5cRKxfcmQwocdfcaESomgqDEkgLvMQywvwPJwpOyYYiNa/pdtz63CImBQaa l5CcytKrEbmYRgJdXHBXV8EXrm2rXkJRgqFeol0Y/L/pby3/roOv67HGcOnPZzQZLvSO XU/m6ksEQTRpm92iVrJHO0Fppic44cQuJS3yHPgjU4s9Xdsmg7oikUkO5y6SvEsl6t/R 0E9Q== 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=LPCpnczupXrz9W1UzaA2UvvdLj0jWSqGpTMR1qrezRc=; b=wzOuhORXfg9cIUAcBDdMioPYXcvD6hTj245LPpxvX2cGSXzPyEVWly4enLyDkSjuXJ kq0pmYQ2K3/eRE1uFIOXOMyYSZXLc91bZBVoJ0d7RkS3I4E54ERqG+iQUECCxG3a+Vpo TCcLix3ehnJzOjVIAcxGN/LM2noCqEGffYxTS23jLvjfA6xVDvg9YB4iET3wkiyMRnQ8 aqOFeqZ2HQL3Zg1ctXwO5nALkjSnST9a0f2QBIwUeSlWtTuj+XoJcdZ/168LW29POk53 GAcTPQo9S8lQtpO5Hl5mTygF/c4z0ukHL2cgOGRhOU4T6eA7AJ7t31c1NJzdO084LwSd QI5w== X-Gm-Message-State: AOAM5338fKcoCy/mOrLIO1/XlCmMry2wtekJDnvqBqFEl6qiKfqkQlPO Evqf+HaNdb739BSihVprtd0= X-Google-Smtp-Source: ABdhPJwCMo5cFS528QF7M7+g4FlKjpTer/lx3c1HJe3wVyPnxmbURlL20mxjfogl83/wbhAGgklMGA== X-Received: by 2002:a17:906:36ce:b0:6d6:e540:ed65 with SMTP id b14-20020a17090636ce00b006d6e540ed65mr6779637ejc.330.1646589075664; Sun, 06 Mar 2022 09:51:15 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:15 -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 05/26] usb: gadget: udc: at91: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:13 +0100 Message-Id: <20220306175034.3084609-6-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/at91_udc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c index 9040a0561466..3578b061a3ee 100644 --- a/drivers/usb/gadget/udc/at91_udc.c +++ b/drivers/usb/gadget/udc/at91_udc.c @@ -704,7 +704,7 @@ static int at91_ep_queue(struct usb_ep *_ep, static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct at91_ep *ep; - struct at91_request *req; + struct at91_request *req = NULL, *tmp; unsigned long flags; struct at91_udc *udc; @@ -717,11 +717,13 @@ static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&udc->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) { spin_unlock_irqrestore(&udc->lock, flags); return -EINVAL; } From patchwork Sun Mar 6 17:50:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548841 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 C1BCEC433F5 for ; Sun, 6 Mar 2022 17:51:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234006AbiCFRwS (ORCPT ); Sun, 6 Mar 2022 12:52:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233993AbiCFRwM (ORCPT ); Sun, 6 Mar 2022 12:52:12 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5793B3EB98; Sun, 6 Mar 2022 09:51:18 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id g3so4774748edu.1; Sun, 06 Mar 2022 09:51:18 -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=G2FhH0yga+1ZprCyQ8mgWVZmrZ4lYY4UAJgQ5E8IQzc=; b=E+Qu6ocw4n+hihu8xQkn9TyfRI6EjpCzNlRGG7PUu4KiFLnoJ36WHQfqSeqZTkvsR2 FmxTx3vplf2nc3NObwZ+fLkYSAiXjjCJwXFqRkrdnHGJFEVWzHtAuFr/pWnInOMEAauh qp/DmG1rDmJldugEceQ1svH1aW2YjpB07YO6VarNMVb9cLipU6a8bvC7mAUxpW6H6rMc BF0PiBJ9DnkWShnWGNxeRVGVXLPHxIDhzDgM5KyRZZTWuI20A87byFbdeYVnf3ZiSnTp WYuvCRH68lQWANBZrUNsjedpXd5sv1SGjSmYYBk7IaNPLbQ6/xioA9m2tkVhnBYDgbaE ZX0A== 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=G2FhH0yga+1ZprCyQ8mgWVZmrZ4lYY4UAJgQ5E8IQzc=; b=UT61dBkv6BwNlH7QvR33QT3LdljJZqt3ASH9qQ0NLLFE44wFCzQWehunjUXznrV0MF aUwL7pWVO6Pl92NLFv7kZPFvy/szXwaoXCjfw78rV/c8n09cJ5C0z4nZmDr7r+WQ8g6o nK0DU8/KRUAQdxNY9vlaphy/Zu+xZdf9W91A70BjEFc7s0ZY6fqLGN+ceKOby7kp9OR0 RtCl1ugX9SL3Mp24J0zCVm6LqfgLyaRwUpc4mPwZ61GfC59B/NtABqGE+jTeqtQUqhW7 fnd2Eu6f70NeXM8XCWmSIjrtHACIe37BIKqhpgZfJZ2JeXJiviQiMjj+GprwFYWh3mPj xo+w== X-Gm-Message-State: AOAM532weCQqBoalKRbrHk73a6Dkxut3GylSrDBDB/cwPzi7CrO6S1vi k8o6yDcce/yRAD4i+OH/Big= X-Google-Smtp-Source: ABdhPJxBACPTk45fBGxLU2gQWl32g17pMRNIekQbZ7gghrWUnArd8SeXplL2CSP3jmthRQTNkokIHA== X-Received: by 2002:a05:6402:1e94:b0:416:44fa:ef49 with SMTP id f20-20020a0564021e9400b0041644faef49mr1862665edf.0.1646589076847; Sun, 06 Mar 2022 09:51:16 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51: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 06/26] usb: gadget: goku_udc: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:14 +0100 Message-Id: <20220306175034.3084609-7-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/goku_udc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/goku_udc.c b/drivers/usb/gadget/udc/goku_udc.c index 3757a772a55e..62153e964655 100644 --- a/drivers/usb/gadget/udc/goku_udc.c +++ b/drivers/usb/gadget/udc/goku_udc.c @@ -809,7 +809,7 @@ static void nuke(struct goku_ep *ep, int status) /* dequeue JUST ONE request */ static int goku_dequeue(struct usb_ep *_ep, struct usb_request *_req) { - struct goku_request *req; + struct goku_request *req = NULL, *tmp; struct goku_ep *ep; struct goku_udc *dev; unsigned long flags; @@ -833,11 +833,13 @@ static int goku_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) + list_for_each_entry(tmp, &ep->queue, queue) { + if (&tmp->req == _req) { + req = tmp; break; + } } - if (&req->req != _req) { + if (!req) { spin_unlock_irqrestore (&dev->lock, flags); return -EINVAL; } From patchwork Sun Mar 6 17:50:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549179 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 68D4FC4332F for ; Sun, 6 Mar 2022 17:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234028AbiCFRwV (ORCPT ); Sun, 6 Mar 2022 12:52:21 -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 S233996AbiCFRwN (ORCPT ); Sun, 6 Mar 2022 12:52:13 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE75F3EAA4; Sun, 6 Mar 2022 09:51:19 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id q17so16993183edd.4; Sun, 06 Mar 2022 09:51: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=L208aYUAvmFOwTViVL6XBF7RZqXvYjdGwfAretzWmg4=; b=IoYTvM2bWygIsX2CvCBMpVLCoYblVVcewWXibtWmNz44ymmV4bvoTn/B+T3Fw0PXpY ZiEF0kClQwdsKnOI8e64l7Zo0lscHSHjYhb6gMs9p0swbveDIt3qNcVM3QXFCn6NOaV+ FgNPitHO9r+cc0yXIbslu//pRFY4lLdI4Am9mMkcco36GDh53Z+MP38UFKnF2x7/tV1A P6n5UNfiRxPO8wR9F0mygdvQv3/t+NA+nGUDOPpNDtm69Bj3twUZzISJZL8bgJk+zNhs 4ctk2Wq6IBvOQ5u2QoKHl8q003AXfsnT9bD8osXHsrevQiDVd10ckj1tARDEgQpuvmBr Ui5g== 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=L208aYUAvmFOwTViVL6XBF7RZqXvYjdGwfAretzWmg4=; b=UbLCw/ovFWoXjczjbULZTEUOhE5d4aJdd8VJmCXdGk6Fg7YK9Fz/mttILGbOmJrhhn eZGAe1lDt5xX3gO2oJ5UgBAGN8rmu6rhUdBQEed4T4rkgL3iS+Y9GTXVMvYmPwJSs23K 79CEZc8J2txJ82ZT0gLSyva6KZKpck11aYkPrpVQxhkoad4GM1/pi5lSpPAuC+kWPg7+ sKkZP6+gRTJUE31IgUoPoTrxqamPf49QOWSeVtpRLO9kpcoPtpZL+MKUUcCFDcWNGult ZS0yjuNRC/xSZkmZcfgkYP0uBJY0typCe7k3KGPFzJ+/3IBdTWWyMh3ib+hkEX1qIAyG wIHQ== X-Gm-Message-State: AOAM531xCeR/BWXNe4uxMYjPjsEhJHy13dYE0CVEBGXO4V1s3ZiJjdVv lHZnOuAE++NEBQ0NOIP6xhc= X-Google-Smtp-Source: ABdhPJzD47Zne4IS1X9b9Z2sK1bFOiRvhA0Sie6iMQ7R1415e4lDmSgo2DW52B9gVPgcbIvo7OjAgQ== X-Received: by 2002:a50:d80d:0:b0:416:1093:9a8d with SMTP id o13-20020a50d80d000000b0041610939a8dmr7905877edj.28.1646589078150; Sun, 06 Mar 2022 09:51:18 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:17 -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 07/26] usb: gadget: udc: gr_udc: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:15 +0100 Message-Id: <20220306175034.3084609-8-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/gr_udc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c index 4b35739d3695..9a940c8f1664 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, *tmp; 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) + 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; } From patchwork Sun Mar 6 17:50:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548840 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 D682BC433EF for ; Sun, 6 Mar 2022 17:51:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234030AbiCFRwV (ORCPT ); Sun, 6 Mar 2022 12:52:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234007AbiCFRwP (ORCPT ); Sun, 6 Mar 2022 12:52:15 -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 E63283ED05; Sun, 6 Mar 2022 09:51:20 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id bg10so27492254ejb.4; Sun, 06 Mar 2022 09:51:20 -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=3MEN8BkVwGONO6rf4oHEkv2XnGVYH4Y2hOyHB5gTgdc=; b=Lb6bciygqlIU9k8Og7P0lKRcEwndfuccYEAwLF0g5QHqH+NRevi1EaoIFKgRzLK4X8 NBQZvnfouGvDLv8lezrBxCOWJlkspHv0xdda4CexewXs4zu9l694VKE72HlAm7n3Xyv/ /4D9/AbmQUt7G0bAhDNJ3q13hGsn60qTe/Ur+yZxrbV2/CX/WHc6vvCM+W4ve5lGQgk7 ivpc3cnTt6ltzX2FaTIBFhyaJrZ2YxGg9eqYVcPs8eybPVatlrVTXcdLrY6Hl2xuT/n4 5E+1mnXyvt6PZowXxwrXwAyspgz4YlLzsqrjrAwoqIorYHvV2Xuk6kOHkJr/zsJ5Q86E h+0Q== 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=3MEN8BkVwGONO6rf4oHEkv2XnGVYH4Y2hOyHB5gTgdc=; b=eyuWTIXuGZLAadR/97jaLGJMlgxh4DYu4YRX7LMRc5us42GC7FY10jv9ruIMoG/7UV WHpTnmZgBATvixzQSNQt7u4SYoifqtVDGorEoEqtAm34opBtHqD3Fl78SpsPnu5ROr3K Q3iHwtTgiZPSMmWFWXdO7nMUv0uqZjwgGdbzLuuVOHrvJTe2YqV2rIWuEsDRrHqbqaoR L2izdTCViycGRyLyP5j0ipChIhkFrBaPLmHx5Tfo4GT8B7hs73wxPWePqsb5OEzD0zj9 FfzSs8Zb6xCRfKFjqxP7QAY/q9GTDPl8Mm483tD6kJDtebp6W3a/o84XYOVjCpa12pjq wGRg== X-Gm-Message-State: AOAM531dWioTcOdTW0jI1oJx2uWXmZygCG/zpX45RlFG2tg9/G8Ju3jp OK9dIg4HMI1vW4xi5744p+s= X-Google-Smtp-Source: ABdhPJzFuOz9Hj1XbpoGODW4cdhLhOjtj/glXonjgnix14QuEnG2iIifoF5PBF8a22LS7/Qr7eHlRg== X-Received: by 2002:a17:906:66cb:b0:6cf:e4f7:9504 with SMTP id k11-20020a17090666cb00b006cfe4f79504mr6692389ejp.142.1646589079445; Sun, 06 Mar 2022 09:51:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:19 -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 08/26] usb: gadget: lpc32xx_udc: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:16 +0100 Message-Id: <20220306175034.3084609-9-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/lpc32xx_udc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c index a25d01c89564..fbb235b1f23f 100644 --- a/drivers/usb/gadget/udc/lpc32xx_udc.c +++ b/drivers/usb/gadget/udc/lpc32xx_udc.c @@ -1830,7 +1830,7 @@ static int lpc32xx_ep_queue(struct usb_ep *_ep, static int lpc32xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct lpc32xx_ep *ep; - struct lpc32xx_request *req; + struct lpc32xx_request *req = NULL, *tmp; unsigned long flags; ep = container_of(_ep, struct lpc32xx_ep, ep); @@ -1840,11 +1840,13 @@ static int lpc32xx_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&ep->udc->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) { spin_unlock_irqrestore(&ep->udc->lock, flags); return -EINVAL; } 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; } From patchwork Sun Mar 6 17:50:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548839 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 38CF3C433F5 for ; Sun, 6 Mar 2022 17:51:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234070AbiCFRw1 (ORCPT ); Sun, 6 Mar 2022 12:52:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234017AbiCFRwS (ORCPT ); Sun, 6 Mar 2022 12:52:18 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76A283EF1C; Sun, 6 Mar 2022 09:51:23 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id a8so27438255ejc.8; Sun, 06 Mar 2022 09:51:23 -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=VYi/beh9rJs36gpPBNet1E5ZiL+QvpMPfNd9I4oRK5I=; b=a7pFL7YgsXz5wRHcetRqppCUPSvnDurx+UuP/B5/03SGZ5AQCyjn7XWWlWI19c6N79 CCP6tlA3zxpmJMqH7LzugOBnbDYoAJ+aY6nvHPgoeGN7fLOYjBPjNluFqtOmoK0rZZvH UsN+qPAoeHTnolilx3Ag7LIAE8J+fCjE779jHRAK8hqYqYzbVHcCXBDu5sKuEUDZo+27 M0W5nAKnGvg2BQMz7eMBvgaN0I9cXDLDcuN2/Mh2vd4KFE5OtOWmQNDxNmpiUSlxZ1t/ 3rlp1m/EbL9gj5VtzGwTbtywjw3KkRNwQHO0sWs7xBCUL/wprcoEJoVdHcyRZ/6KOkXP Y92A== 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=VYi/beh9rJs36gpPBNet1E5ZiL+QvpMPfNd9I4oRK5I=; b=s6FrBzDLEQN8LTWzn8W42CwAcd2IGsDM/J5alPOpzuIke08oP0tjufy/SjoNlWS96T 56n0ckzAUBX9f6DTx9D7v7a7z6aXQc2Uvp8xO5XVDpKJAxjsi8A6P6wZheNn0fUxBSsP Q5FH/ZAd10G41VlTgIsJIjJI5LIt2I/VBe94DFHGudMEq607QQcaYmcvZ4w5woJQrJYs aH7HM6Im3fUSQECpegD3yvL0nQzFRNRjF1cMwp3xzRI069xdA8nA69nNpxBnH8wwPXXc aR8kC9GRzkCwMknIiB00J/+CLCl9tPsx+disntJ/uOPmxSLHjDPsNnGbWdeYwENPkfjy zQFA== X-Gm-Message-State: AOAM531yN5cqcoSm7EyzbiKiV/pl+GhQLV3jGm2sD9mpQ3LI19Y3OnH2 rWWADXY6p9fErbVi/CRFqnM= X-Google-Smtp-Source: ABdhPJyY+AsNP0zi56hP3Xjcd93Gh9olWpCas99mAx7qP67Dy550ZiJkzvNPQMQdredYm0hGz4HOqw== X-Received: by 2002:a17:907:7f05:b0:6d9:89e1:3032 with SMTP id qf5-20020a1709077f0500b006d989e13032mr6260495ejc.320.1646589081967; Sun, 06 Mar 2022 09:51:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:21 -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 10/26] usb: gadget: udc: mv_udc_core: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:18 +0100 Message-Id: <20220306175034.3084609-11-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_udc_core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c index b6d34dda028b..67d935d29cb6 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, *tmp; 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) + 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; } 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); From patchwork Sun Mar 6 17:50:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548838 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 2C261C433F5 for ; Sun, 6 Mar 2022 17:51:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232643AbiCFRw3 (ORCPT ); Sun, 6 Mar 2022 12:52:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234052AbiCFRw0 (ORCPT ); Sun, 6 Mar 2022 12:52:26 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A3F3ED12; Sun, 6 Mar 2022 09:51:25 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id gb39so27430065ejc.1; Sun, 06 Mar 2022 09:51:25 -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=NFdMMV5Ey1yhbuTg2uQcwCqlUE+qS+Y12f/YYOvaHuM=; b=fh1SkZYAm3ePAk1Mtk/gHZqOd7f/fC7MnFMjF30YjRSDV/IwHeJr2wNdsG35DduIWD pDxUyNzCjL70TJv8k10SJhRlFYWBTCB0e3zzb1YdODkL3j0k8O7+oT6Ws8Hi3DxlF9t1 PIPFKk0s5NWyLqKrvHBGrWL/jsIT9KMTJNZPVlq5H5DBcuMDGju7U+rlnXh5YdSmeaSe xWoq2DLDsaPRnXyz9AOcJVwr6DSdN950NFV2Ja6H9sc6M6hhFy/vuvGO40qV309/UfnL KIhmXk865a67Qt0EjSsUcOf5g6cRyJqrxq5zQ9xOrNr6FoupVGqGZMWaSVchOV0yG2K6 k/Yw== 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=NFdMMV5Ey1yhbuTg2uQcwCqlUE+qS+Y12f/YYOvaHuM=; b=tDlIiwFAEqQEWIIlUXLn6YCiLrK7kM10a6ZMSP0AUFgUcf61YvN/nxFmGT8TRxJ8+S 2G3vOlGnkk9qhOwzJgX3RCyVyLSXqTDOTdmQN2ZF6iCE5cl+4PYNHaTpG21lkqLtbXMA pmcQJmL8+wQIXBJhB9uOH+6VRSB99C7grc1gQlcEekrOLqwVk9tFn1A9Jre+IsDTbitM ZFv1zzmzvbCCRC5vOZpX4X6YkHS89ur3chiXSg0/pD7W9WeM4zLiw6M4YPuSK36GbAXT lul1bj/PudnG21fki4HR6l+RmEv6Ska9MUi+g6s67yiKtbBnGnUD6tkRA1ZUFYl2A1uR 6nbQ== X-Gm-Message-State: AOAM533nMEtF+b4JazdPoINQt6lpxbb+y8wyuy5tesNQ7KUaAzWMRoYc 2wWa/WET2cEUjjs146o35Xg= X-Google-Smtp-Source: ABdhPJzJfVGmbCFueAPzln30rBhgT6WIXJ/8qm/UOPNvqiSVEtSUCZ7gxek+/A6tjkBYJF+NnHKbSg== X-Received: by 2002:a17:907:3e94:b0:6d1:d64e:3141 with SMTP id hs20-20020a1709073e9400b006d1d64e3141mr6130918ejc.213.1646589084422; Sun, 06 Mar 2022 09:51:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:24 -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 12/26] usb: gadget: udc: net2280: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:20 +0100 Message-Id: <20220306175034.3084609-13-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/net2280.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index 16e7d2db6411..dbf5592dbcf0 100644 --- a/drivers/usb/gadget/udc/net2280.c +++ b/drivers/usb/gadget/udc/net2280.c @@ -1240,7 +1240,8 @@ static void nuke(struct net2280_ep *ep) static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct net2280_ep *ep; - struct net2280_request *req; + struct net2280_request *req = NULL; + struct net2280_request *tmp; unsigned long flags; u32 dmactl; int stopped; @@ -1266,11 +1267,13 @@ static int net2280_dequeue(struct usb_ep *_ep, struct usb_request *_req) } /* 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); ep_dbg(ep->dev, "%s: Request mismatch\n", __func__); From patchwork Sun Mar 6 17:50:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549176 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 5C90AC433F5 for ; Sun, 6 Mar 2022 17:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234083AbiCFRwc (ORCPT ); Sun, 6 Mar 2022 12:52:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234012AbiCFRw0 (ORCPT ); Sun, 6 Mar 2022 12:52:26 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 335923F303; Sun, 6 Mar 2022 09:51:27 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id gb39so27430111ejc.1; Sun, 06 Mar 2022 09:51:27 -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=Rmkemrzx/JOj9Lp0lV6gklfrqlH7Nd+08eNmWTNXfaw=; b=RlPKuH/Q+b8lka1W/roXH6bVEoeOC0bFjtLQEoAl8bsVUuIKYQGhe5XH6YVOMIIBlu KNz9hBp9oD3qgQuOz1N7sUcuagtV7Gvm1AK7Elk+B/ulRqejs2wIhgHkuLHVjHYUwmp/ FObh52tssEQFnYJF5WPC4V/t68ErcDZi6rZIBj2MPg7H5/PFbcFD8+rlnRk4cvzyljhO EyeC6NgWX5A90N3mrKet6OzTPQJ7Jmw/NZ6B+okQ2ERKP1Jqwj3Rv2m1QfgLBMw7lweG ml54H7twz9SkOneS3urr2iTAmcFFuIFa854zkoHpN3rpON7M7nW/J/EtnIEuYja9ToPz q5lQ== 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=Rmkemrzx/JOj9Lp0lV6gklfrqlH7Nd+08eNmWTNXfaw=; b=JJJYIONoK4LJfb2YGPgEz4LV8EB+DPvfuBEA63r41yqje2lUexRBHQl5N5igS9tVw2 fWudWSMuUQIAipJDxttEXbUzzFDXrpiQaKNpuzPb1sq1D0Q+AdWmRGtwnr+1prr4GQrI bSt9qhtSE4tL8htZpgXHN/gDBxwlQ1K0zZDJ9TaZrb/8FV/izT5XTJL16rWHYMISQNZg 8TeqZy3LaJv1XoILLQT7UY8ynw9b1TKlwhO1Fg1zHjfvGOPyz8i2e4IryfPVxrr/9ki+ 13borVIgVHBwRV9ewXHcOMh0ECWMHSuqRgdZ3dmlP2KchxLErLR5h3Oi9n6OJCgnlAD4 urCw== X-Gm-Message-State: AOAM531wO7c+65QI0/RkuxvWUCjoJsRB89oBqowwpODOhiumRinFgG3z 2yYNOkpxgWw0bZMlzqjMd38= X-Google-Smtp-Source: ABdhPJyMA6ISo3GDhlEbHcpWhfyLwjDly+XGmCjMcbI3GH4w07Qtpq7UHDdo5QM7xnm715DMHBaHmw== X-Received: by 2002:a17:906:16cc:b0:6ce:e607:ff02 with SMTP id t12-20020a17090616cc00b006cee607ff02mr6230706ejd.418.1646589085648; Sun, 06 Mar 2022 09:51:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:25 -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 13/26] usb: gadget: omap_udc: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:21 +0100 Message-Id: <20220306175034.3084609-14-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/omap_udc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c index 494da00398d7..e48a89baf44e 100644 --- a/drivers/usb/gadget/udc/omap_udc.c +++ b/drivers/usb/gadget/udc/omap_udc.c @@ -1003,7 +1003,7 @@ omap_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags) static int omap_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct omap_ep *ep = container_of(_ep, struct omap_ep, ep); - struct omap_req *req; + struct omap_req *req = NULL, *tmp; unsigned long flags; if (!_ep || !_req) @@ -1012,11 +1012,13 @@ static int omap_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&ep->udc->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) { spin_unlock_irqrestore(&ep->udc->lock, flags); return -EINVAL; } From patchwork Sun Mar 6 17:50:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548836 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 11623C433F5 for ; Sun, 6 Mar 2022 17:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234063AbiCFRwm (ORCPT ); Sun, 6 Mar 2022 12:52:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234023AbiCFRw1 (ORCPT ); Sun, 6 Mar 2022 12:52:27 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59DAE4132F; Sun, 6 Mar 2022 09:51:28 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id d10so27427109eje.10; Sun, 06 Mar 2022 09:51:28 -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=+laazn1CopjYa20d+WHM4bkWo61KY20pgKEJdkgNZoo=; b=J3rodyH1WlYVoUO0kqbj9dBFM00KrNZIc2lpsI7rqSFubeDQjNO5bv1Y/HdeakucFf 2DrG2YBBiPJxoL/CLyneZwoUhrgBDS+lVxn5oSfNNhWKoIJwj5qP1EM6OK1bu+wFlYwr WPOanxP6W8nMvnjnMgMD+EXwoM5O2u2mwP4VpjAWrNSSZyI7DbeF/dlFTTx+3LdB/GiF p0RLfQy5VJf2SkhJm9hZZMvYzcSZ8G8Ym/KnY63tos1H36uHzK5NlzaL08XHRR1OPfuo itI54Bv+knGvasu1kDkRt+82Pc5I+KQlg3JAkozyxzFcXoMYcQz+7+COwWdap223YLwI GwLg== 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=+laazn1CopjYa20d+WHM4bkWo61KY20pgKEJdkgNZoo=; b=N+a0zC2bVUiUGOiW2EukvBGlxxIG5MaKdIoVRZIdg+ZVmFsV43Iw5rKkzSSnPI4l96 3ZtJ2p8BEwoxG9keNruGjPookFWDg02h9glyw38DsOSGgmq0bgjVOmYAKDO5H3CcvH4L Ts+r2JZ4T9YQLut2nAZDCQKeJNEPHe5bBlUNxEOYmpgsDeqBiutB1VpSgCnbPXfXRoYg gQuFmiv7jQTNIYhEOxCK8mb3tTnLSzFkNsRm1kqIqlFawoIZjFRuQyXxabqu7phjIXUk wnDBaAhy33jIZ9XTJZOuEyU+26VqzUwkA55xUGeLpPPqXVnXunsckdy2Yh0YCTtlt4zu ioSw== X-Gm-Message-State: AOAM5332lRmZttwVIY/cYuvVUCpOS2sX7hGFmB2wzcWHaW7NodcL0M9h qwkOR24RrtzM52MZKkgeZUQ= X-Google-Smtp-Source: ABdhPJxhoEeJNQ0cMQH5hmQKGphrFV8eRPY932fnE2Yvg6TjrjBkipqTZEj0B1kYEbqYyNX9gxOrLw== X-Received: by 2002:a17:906:6a81:b0:6da:d7e5:4fa with SMTP id p1-20020a1709066a8100b006dad7e504famr6311763ejr.223.1646589086810; Sun, 06 Mar 2022 09:51:26 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:26 -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 14/26] usb: gadget: s3c-hsudc: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:22 +0100 Message-Id: <20220306175034.3084609-15-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/s3c-hsudc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/s3c-hsudc.c b/drivers/usb/gadget/udc/s3c-hsudc.c index 89f1f8c9f02e..ddfc30b1d248 100644 --- a/drivers/usb/gadget/udc/s3c-hsudc.c +++ b/drivers/usb/gadget/udc/s3c-hsudc.c @@ -877,7 +877,7 @@ static int s3c_hsudc_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct s3c_hsudc_ep *hsep = our_ep(_ep); struct s3c_hsudc *hsudc = hsep->dev; - struct s3c_hsudc_req *hsreq; + struct s3c_hsudc_req *hsreq = NULL, *tmp; unsigned long flags; hsep = our_ep(_ep); @@ -886,11 +886,13 @@ static int s3c_hsudc_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&hsudc->lock, flags); - list_for_each_entry(hsreq, &hsep->queue, queue) { - if (&hsreq->req == _req) + list_for_each_entry(tmp, &hsep->queue, queue) { + if (&tmp->req == _req) { + hsreq = tmp; break; + } } - if (&hsreq->req != _req) { + if (!hsreq) { spin_unlock_irqrestore(&hsudc->lock, flags); return -EINVAL; } From patchwork Sun Mar 6 17:50:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548837 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 65CB2C433F5 for ; Sun, 6 Mar 2022 17:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234054AbiCFRwf (ORCPT ); Sun, 6 Mar 2022 12:52:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234053AbiCFRwa (ORCPT ); Sun, 6 Mar 2022 12:52:30 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EAD949903; Sun, 6 Mar 2022 09:51:29 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id kt27so27576799ejb.0; Sun, 06 Mar 2022 09:51:29 -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=l//L7ocJGxqmRL5eS8666SYNKXhr7tX6wV7H1PEFO9E=; b=oM1vSktxE2Qr655ln7crRO/JCD5alzuN5GehEboD4d3pPEfnfRXPXwtGqHtPmzqC+Q AHEVWbibeibbpKr7SoPQTJWdXWME7xXZ2Y0g9GkAiwkBGbYvw1Cwc1bFjkJL75A9IYA7 gbb6/0SrZEaIF4iq9l4NdHKO7eyWiZa07lbpT4rF+IVeLtcteDs8L/dJZsNJot6TfO3+ I/sGZxCUV3T754Zr+SB072WVlEKfInG1RuqyR0fa4GMz4Nn7SVQDbssvq3jhSHDUgnOU /71LXM5AX+u1FeIITq9zCZ5+gv6MK018+GgSA7If2s7d+o2vpePtQMnbHx2tR8ZWiwdP PgPg== 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=l//L7ocJGxqmRL5eS8666SYNKXhr7tX6wV7H1PEFO9E=; b=2e5BGMf4wiDB5SPMb0rhKSVObo6RMIFjjfO91Uw5f7DcqtfVRUqjP5qo65ileS7EJf WDUZfk2W1/UMaUcRkKOZU3G5bq/+L+9muQSBKNW9MEGXJni0evgBlK30hWhh9LgXTFoj ++y20bK/YD0pdcj2p+7sufa58FR1Rx5jzzk/Q8KncrFD3h8ddpoVOeo2hpcNh7ZrH4Rd PbvD00TU6f5x1E7nC9hZsF1DJgEmhN83Y8hFe5TVuKc3lvKqeSM3q1ibz+IG1fMmwhN+ dreFKOwljYTycJsAubzwmb1AtX8UHCB+0qLZHTIjpfwgm+OjStAdiujGjRfqy2v1TtVc ILUQ== X-Gm-Message-State: AOAM531llO/miJc64G1KVoF23+NJVAd10HDRzShmZIV8TcjH8S4KhBOF XLb5q1JHxWt8QOgDNckZdjo= X-Google-Smtp-Source: ABdhPJx2VALjSdYBrZOfqyUmLmttVyLFzl8u+i6UgxBZg+en7rBj0SWM3EOhinsX10v2bBcLPvv0Lg== X-Received: by 2002:a17:906:5597:b0:6ce:f3cc:14e8 with SMTP id y23-20020a170906559700b006cef3cc14e8mr6410110ejp.426.1646589087983; Sun, 06 Mar 2022 09:51:27 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:27 -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 15/26] usb: gadget: udc-xilinx: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:23 +0100 Message-Id: <20220306175034.3084609-16-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/udc-xilinx.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/udc-xilinx.c b/drivers/usb/gadget/udc/udc-xilinx.c index 2907fad04e2c..34b7000f0602 100644 --- a/drivers/usb/gadget/udc/udc-xilinx.c +++ b/drivers/usb/gadget/udc/udc-xilinx.c @@ -1136,17 +1136,20 @@ static int xudc_ep_queue(struct usb_ep *_ep, struct usb_request *_req, static int xudc_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct xusb_ep *ep = to_xusb_ep(_ep); - struct xusb_req *req = to_xusb_req(_req); + struct xusb_req *req = NULL; + struct xusb_req *tmp; struct xusb_udc *udc = ep->udc; unsigned long flags; spin_lock_irqsave(&udc->lock, flags); /* Make sure it's actually queued on this endpoint */ - list_for_each_entry(req, &ep->queue, queue) { - if (&req->usb_req == _req) + list_for_each_entry(tmp, &ep->queue, queue) { + if (&tmp->usb_req == _req) { + req = tmp; break; + } } - if (&req->usb_req != _req) { + if (!req) { spin_unlock_irqrestore(&udc->lock, flags); return -EINVAL; } From patchwork Sun Mar 6 17:50:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549175 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 44321C433F5 for ; Sun, 6 Mar 2022 17:51:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234114AbiCFRwl (ORCPT ); Sun, 6 Mar 2022 12:52:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234089AbiCFRwc (ORCPT ); Sun, 6 Mar 2022 12:52:32 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4C09506EB; Sun, 6 Mar 2022 09:51:30 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id f8so16968780edf.10; Sun, 06 Mar 2022 09:51:30 -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=iIKVutnxEysZ3U/cjNJKuYZZfTcEA1ZCqcm3z1Xao3w=; b=UleLf2dhL9Szmy2LjLz9bQqE+eNX2Zqw8wroyzAwLb/VV9+tWkFka18JPNNO1s1AXs 8gmaSD4orpEcgiczNCZ+hkuaGoXWwNDuHxJp/amJ99N8sAoP8ml+d3VaZlzE55iNF16J OoDGdQy/Zkcdg1F2ApRIppgjy+m75qOdYe61TgDqqoHQ6L7C9QeX1c1gnlQJq3SFM/6F 4kJxaUj0F4CArnHBoWYnzTv9xAPyBgny/nTEeAdzjl8o9IZ9lX6BpmI0VoaLoL4K+BAs bvgCqC0VPqnQgTQ7DjesQ8Guh+OBWAyUDOKGHZaflTumfX1XlIpD2kKoFoHLG12Res+Q WPiA== 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=iIKVutnxEysZ3U/cjNJKuYZZfTcEA1ZCqcm3z1Xao3w=; b=PSgqFgilViN1o4tiAOmLYPoQ8ASTcTYfYwgb8hUf02Q7Pe+WAb3+zJsEPreT9AUzdh ZJOoxTHd9a6lTj6Gp9lSN9x080+kiAlL+ol3g0FtLguJ0m3/gIaCjgmi9XkVfPlzCp5p c1R9qjsYmfq3g94xxfScIDVgZ5VzbLT+Eu6abJ/gN8aVvih1KP0TNp/8vS+Nmvg27HGL 37smw0iJ1AVHpzhm/Kng+o6qOPVH5fCRzMhFHJ9b33ybLeTSi+Y50zPMrSUJxJzCiVo9 csQqNbS0tZpFr3jlejlZKfbeTK/XXI29Zgsbq1UFYwX3z6DizpAx+txSkmw7KyDcCZI4 Othg== X-Gm-Message-State: AOAM533mImQO5hgZedez5a+thcnKCqGNk0kCpgWiKqXJzzlhMc7+E6Zd Q3jAdwkuQXpc1ALV+cAPVBg= X-Google-Smtp-Source: ABdhPJw9Wrru6dPfApYi1EfgKhejBh/FB2r353EJTeD8/6lapCo8eTErkF1EzwyH+mwoYjOGCEWRSw== X-Received: by 2002:a05:6402:442:b0:416:14b7:4d55 with SMTP id p2-20020a056402044200b0041614b74d55mr7575292edw.183.1646589089229; Sun, 06 Mar 2022 09:51:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:28 -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 16/26] usb: gadget: aspeed: remove usage of list iterator past the loop body Date: Sun, 6 Mar 2022 18:50:24 +0100 Message-Id: <20220306175034.3084609-17-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/aspeed-vhub/epn.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/aspeed-vhub/epn.c b/drivers/usb/gadget/udc/aspeed-vhub/epn.c index 917892ca8753..82b54b6a052b 100644 --- a/drivers/usb/gadget/udc/aspeed-vhub/epn.c +++ b/drivers/usb/gadget/udc/aspeed-vhub/epn.c @@ -466,19 +466,21 @@ static int ast_vhub_epn_dequeue(struct usb_ep* u_ep, struct usb_request *u_req) { struct ast_vhub_ep *ep = to_ast_ep(u_ep); struct ast_vhub *vhub = ep->vhub; - struct ast_vhub_req *req; + struct ast_vhub_req *req = NULL, *tmp; unsigned long flags; int rc = -EINVAL; spin_lock_irqsave(&vhub->lock, flags); /* Make sure it's actually queued on this endpoint */ - list_for_each_entry (req, &ep->queue, queue) { - if (&req->req == u_req) + list_for_each_entry(tmp, &ep->queue, queue) { + if (&tmp->req == u_req) { + req = tmp; break; + } } - if (&req->req == u_req) { + if (req) { EPVDBG(ep, "dequeue req @%p active=%d\n", req, req->active); if (req->active) From patchwork Sun Mar 6 17:50:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549174 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 E1579C433EF for ; Sun, 6 Mar 2022 17:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234122AbiCFRwo (ORCPT ); Sun, 6 Mar 2022 12:52:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234096AbiCFRwe (ORCPT ); Sun, 6 Mar 2022 12:52:34 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05E503EF30; Sun, 6 Mar 2022 09:51:32 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id p15so27459368ejc.7; Sun, 06 Mar 2022 09:51: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=2lnsjgc8gTgQJKHb5cwbwqNyvDuf7SwnwUQTslH8JIg=; b=NUkgQni0X1/qeySbGiP7hm5BAvV+9Q/VvDRnNz4MWc5wa3HELzvzA64dM+BsUqK2f1 KX/cn1d2QSgwIJPbSU0DlmE7K/JjGfn/iTnhaeV62PSkYCUDFTFyzK+T9Sm6wMG57UEl teGnJjgldP1mdgxErJt4Pqyrxy3rPHJHFEu/nMaV7O6bFwOsEJeWhSbakTMq+cKXGYuF Yy4sjs9dFPKXsz3F06+/1QVHwbCFcwKB9Sll9WH9EX9MzsEYCHC5BWeEt8HvVO+zhKY1 Yz5klNdlUO+Ro1IKWhLjVytM+9mpAZ4Y4/+eJlATFBOg0G+vCkNX7NundYOR2Hzx5Jym lIEw== 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=2lnsjgc8gTgQJKHb5cwbwqNyvDuf7SwnwUQTslH8JIg=; b=itSZMnnsDQ/w0DCHFasaEoF2gBGEZu1qJrNDFEy4O7ZLLtb2CLg/kaWiMGCyxSeyQP xvdk6gAnwXErHrvM3B11IixOJYLS9CJ0iQCVSWYq5bN80waRYCT7b9l72ltO0AQLMk/p 6HNfHNEBK8fKzWQ4SW1I5ExNzBsnG4M+m14OmAq5TxkSocUP5z38rZNWCXTKk8KVNnyz dS1pquEADBltrOnAtPQ+ggKTFSAqaP0wJbHCXmjHZ/W0Y8cbdTWg+cJhjw1KaZOP5B62 oFisi6zfpXgXcsIwRoDfSxrffan7tOctXT2dOw63pNzlY+3z93bzvdbag1jzANj4lAnq CG8Q== X-Gm-Message-State: AOAM531m1nuCPK99L6X4ws8EftTOBfJL9LPQgOkRhs47DLZmOqVhM1E2 FfhD4su7MjZnSNmC99afJ4M= X-Google-Smtp-Source: ABdhPJxu6+Bb8dW2HuL99DdSI+RhF569LcaEu/oMldym/QqqyufCsU3wFtLHvfoB1DJzp/giTDNjbw== X-Received: by 2002:a17:907:62a1:b0:6da:7952:d4d2 with SMTP id nd33-20020a17090762a100b006da7952d4d2mr6359621ejc.260.1646589090480; Sun, 06 Mar 2022 09:51:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51: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 17/26] usb: gadget: configfs: remove using list iterator after loop body as a ptr Date: Sun, 6 Mar 2022 18:50:25 +0100 Message-Id: <20220306175034.3084609-18-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 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/configfs.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index d4a678c0806e..938cd43e74c6 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -418,7 +418,7 @@ static int config_usb_cfg_link( struct usb_function_instance *fi = to_usb_function_instance(usb_func_ci); - struct usb_function_instance *a_fi; + struct usb_function_instance *a_fi = NULL, *tmp; struct usb_function *f; int ret; @@ -428,11 +428,13 @@ static int config_usb_cfg_link( * from another gadget or a random directory. * Also a function instance can only be linked once. */ - list_for_each_entry(a_fi, &gi->available_func, cfs_list) { - if (a_fi == fi) + list_for_each_entry(tmp, &gi->available_func, cfs_list) { + if (tmp == fi) { + a_fi = tmp; break; + } } - if (a_fi != fi) { + if (!a_fi) { ret = -EINVAL; goto out; } @@ -882,15 +884,17 @@ static int os_desc_link(struct config_item *os_desc_ci, struct gadget_info *gi = os_desc_item_to_gadget_info(os_desc_ci); struct usb_composite_dev *cdev = &gi->cdev; struct config_usb_cfg *c_target = to_config_usb_cfg(usb_cfg_ci); - struct usb_configuration *c; + struct usb_configuration *c = NULL, *tmp; int ret; mutex_lock(&gi->lock); - list_for_each_entry(c, &cdev->configs, list) { - if (c == &c_target->c) + list_for_each_entry(tmp, &cdev->configs, list) { + if (tmp == &c_target->c) { + c = tmp; break; + } } - if (c != &c_target->c) { + if (!c) { ret = -EINVAL; goto out; } From patchwork Sun Mar 6 17:50:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548835 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 E1D29C43217 for ; Sun, 6 Mar 2022 17:51:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234127AbiCFRwp (ORCPT ); Sun, 6 Mar 2022 12:52:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234010AbiCFRwf (ORCPT ); Sun, 6 Mar 2022 12:52:35 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CDD7527D6; Sun, 6 Mar 2022 09:51:33 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id w4so14454949edc.7; Sun, 06 Mar 2022 09:51:33 -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=7L/xs4fx6+L+Psy2Q24Oz42Aj8LhoH2R3t77ruSAieQ=; b=VD93FV3zAZ9mxWdMMOnPObLl522sLSooKrrpc/8aSIViodCPTPH1h8uMcDp/Js704J X5P1/in71tJ6NTm+pijd2XRPN/eytV7XscDN94Z5c0MgKFgdBHYkXIYMY/lmHu/iUvs6 b6Uc6glX0ewfqsqVp2BjswgX+7MBmagZaYi7tJ2e1AWUNPg4wcKMuRu7VYmDYG6h5Muv +fTIRWHLg9uQ43zDw/y2G2nkEHProJ6dlOYh8k87JATXogeoYAIShY0IuI5CwaFhZ5y7 D4GK1I7CMN+z6k9f13aOOZ+9cf9iZ4jisNYZh2sMOwMb3KCUOTPV3XAgMk/MuZH6zHap JU7A== 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=7L/xs4fx6+L+Psy2Q24Oz42Aj8LhoH2R3t77ruSAieQ=; b=qWfHgNCaVtE9Rqgm0zttnDubzxxqmSSbjith8GDXy4XdIygIg/cX71h7r1xKjLnY6W F2dbt0cxagyZGvLL56AIHWcvLGGv6krppsJrVpIWO1g9OlNG4sd6oh5FyK+9YpD3Zfa+ bQYPRoD14fW9Ey4W9ko6AKvf2tC/WPdbBo9bqyiUjYO6EjSyaQ9hvOZPvgNQlxe0gmTg Rt0UV8j9on52X3dDhL9NtjvOs3oTpnQy5usSqRTfzlt2CoOWbJRHkl9oILEzRGX6u5he +WwA3ZJ8KAoc8Who6zvZpXzRrBL2DmqAEaUDCg9N1m8bqDZayxNxEzI4ZcBcLd0sHAEE stTA== X-Gm-Message-State: AOAM530aikbGA77UPqQJ9YvhmIB6KXme8JHezhIGwD1lw6BBceBD40OP /As+ybeOKpwyBGcAn/dcWeA= X-Google-Smtp-Source: ABdhPJzik5qGEaWXA/mY5pY2E48KOsS17nIJHMdyugphkWCPmVeey2cfjVdgaH3vxXegNIVnq8fSCw== X-Received: by 2002:aa7:c946:0:b0:416:226f:f8a6 with SMTP id h6-20020aa7c946000000b00416226ff8a6mr6569335edt.360.1646589091947; Sun, 06 Mar 2022 09:51:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:31 -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 18/26] usb: gadget: legacy: remove using list iterator after loop body as a ptr Date: Sun, 6 Mar 2022 18:50:26 +0100 Message-Id: <20220306175034.3084609-19-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 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/legacy/hid.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/usb/gadget/legacy/hid.c b/drivers/usb/gadget/legacy/hid.c index 3912cc805f3a..b7f1ff2ce951 100644 --- a/drivers/usb/gadget/legacy/hid.c +++ b/drivers/usb/gadget/legacy/hid.c @@ -134,7 +134,7 @@ static int hid_bind(struct usb_composite_dev *cdev) { struct usb_gadget *gadget = cdev->gadget; struct list_head *tmp; - struct hidg_func_node *n, *m; + struct hidg_func_node *n = NULL, *m, *tmp_n; struct f_hid_opts *hid_opts; int status, funcs = 0; @@ -144,18 +144,19 @@ static int hid_bind(struct usb_composite_dev *cdev) if (!funcs) return -ENODEV; - list_for_each_entry(n, &hidg_func_list, node) { - n->fi = usb_get_function_instance("hid"); - if (IS_ERR(n->fi)) { - status = PTR_ERR(n->fi); + list_for_each_entry(tmp_n, &hidg_func_list, node) { + tmp_n->fi = usb_get_function_instance("hid"); + if (IS_ERR(tmp_n->fi)) { + status = PTR_ERR(tmp_n->fi); + n = tmp_n; goto put; } - hid_opts = container_of(n->fi, struct f_hid_opts, func_inst); - hid_opts->subclass = n->func->subclass; - hid_opts->protocol = n->func->protocol; - hid_opts->report_length = n->func->report_length; - hid_opts->report_desc_length = n->func->report_desc_length; - hid_opts->report_desc = n->func->report_desc; + hid_opts = container_of(tmp_n->fi, struct f_hid_opts, func_inst); + hid_opts->subclass = tmp_n->func->subclass; + hid_opts->protocol = tmp_n->func->protocol; + hid_opts->report_length = tmp_n->func->report_length; + hid_opts->report_desc_length = tmp_n->func->report_desc_length; + hid_opts->report_desc = tmp_n->func->report_desc; } From patchwork Sun Mar 6 17:50:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548833 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 6C05DC433EF for ; Sun, 6 Mar 2022 17:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233775AbiCFRxF (ORCPT ); Sun, 6 Mar 2022 12:53:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234088AbiCFRwh (ORCPT ); Sun, 6 Mar 2022 12:52:37 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1F893EAAE; Sun, 6 Mar 2022 09:51:34 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id dr20so27420130ejc.6; Sun, 06 Mar 2022 09:51:34 -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=+21SkvZ1V0/Yykwt/4suhWYPa8wNy+dkzerfqHH80FU=; b=j0sbbeSivVNug0gFNVXL4njiYWbwx0G/t8XpNp2ot9fBGkc/MpuppbR6dq76oV9h34 U4a9R5oAGigRltG4E2uk8LVf3Sr/Q+H5IItb3nj/xqIqPylZABLpRab8JloSPrOBLPYP SbwwnVfEaJOGR7jQcCi5VoarY+iDvxeAEpSZFoxf9vwuViVIpJj5i14UBiphGs7tq6Q/ hIGFu9Goy9U9LBhAz6XYA1tQ+WhrjiEZugaELer4pLcWgtHB1TJuyRV7paYGxGpcPILJ 3GwHXCcRDLlh8APdGthGD+mSejgQPfWUjBFv8SMHNb9JxUziDQunYUTisCu0PpEENUjq 2Y1g== 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=+21SkvZ1V0/Yykwt/4suhWYPa8wNy+dkzerfqHH80FU=; b=Ll75Yf9Q4Nz8/OOlErr6/42+5giFPnkpdwcQNLb3PmGwm3BlTKaMaIKLi49TXo36GH D05mbx1MCzqFfiNKx17G1GxOhqEhoC5AxOdhhDD1rs0y7kCtJR3UfTnprSNjyQwHAZ0v ZssKknnHM+5AFx6keZjyrel0OwF4m9Yfj3HQeU+5hDumnlIB1lXYlzeje4jAQgXMgsX3 KGRtoR77VAbfUa1TXvvLxN+J3+vcllaRqT5mTmxICfcrPlsjJdKST9jQi+i14wLA0wGe gxYFsXVTBo/RJLOYqzh4NtXVorp8XWGeICj0tUY5xp9DMul8mQG8tQTRnsTx30KPOACt z+oA== X-Gm-Message-State: AOAM533Y8I8SDf9hQA4BHvfQ/P0ivmyLwbE5pDxtnE/8wQ+ODFz8bLv+ U7qM8k5MeqKVOqg0kfS4aJ8= X-Google-Smtp-Source: ABdhPJz+IRqxea7CTn4M8DREljvADWarmfOp1KMJjR26UN4FAa8Qc8zIgRSmkU15EdtUT+rM96ZaXg== X-Received: by 2002:a17:906:8d8:b0:6d2:131d:be51 with SMTP id o24-20020a17090608d800b006d2131dbe51mr6483746eje.564.1646589093126; Sun, 06 Mar 2022 09:51:33 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:32 -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 19/26] usb: gadget: udc: max3420_udc: remove using list iterator after loop body as a ptr Date: Sun, 6 Mar 2022 18:50:27 +0100 Message-Id: <20220306175034.3084609-20-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 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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/max3420_udc.c b/drivers/usb/gadget/udc/max3420_udc.c index d2a2b20cc1ad..d1b010b5f4a0 100644 --- a/drivers/usb/gadget/udc/max3420_udc.c +++ b/drivers/usb/gadget/udc/max3420_udc.c @@ -1044,22 +1044,25 @@ 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 *tmp; 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_for_each_entry(tmp, &ep->queue, queue) + if (tmp == req) { list_del_init(&req->queue); + t = tmp; break; } spin_unlock_irqrestore(&ep->lock, flags); - if (t == req) + if (t) max3420_req_done(req, -ECONNRESET); return 0; From patchwork Sun Mar 6 17:50:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549173 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 E864DC433EF for ; Sun, 6 Mar 2022 17:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234112AbiCFRwr (ORCPT ); Sun, 6 Mar 2022 12:52:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234107AbiCFRwj (ORCPT ); Sun, 6 Mar 2022 12:52:39 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18ADC3EF35; Sun, 6 Mar 2022 09:51:36 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id x5so16956339edd.11; Sun, 06 Mar 2022 09:51:36 -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=M3NmIv2lxSwyciO5fMF4SzE6/Z1J/5GfYbZbUZ0NpkQ=; b=GloWxkEKoUd1n3zcMloIVrOvLZBuvCZEyIWCJYqYe8TaK774kpfNhEyp6TgDKNPmGS VkP4epagNT//AJdlnorqgF8WrOeoyJwLIdmPDefytnlMJ4eTXNmY31TFDYpTNRkUzIpQ Ni/a6TyP8Lgnt+DB1NE7UcmKmGVTRaq269eEuazVe9aRVf01aZkftAHuE2+oo95/RjT1 xkpnhRhork+4bL9MP2QRYXzI2qpjJor5GdFEWo+rT/5R8UJIo5s4rrugIXMu0QsLhnvd j6HeoWbk1FJXOzkjmPljO2HjeXA7OFH+HQkJXd3fRyB+5biM4HEzwX0yxbrMsLNOboCx BZ/g== 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=M3NmIv2lxSwyciO5fMF4SzE6/Z1J/5GfYbZbUZ0NpkQ=; b=DeRzDLyrvNUbq1EuDCV0vTHNCQdu0jogs1xkU1RDfBEb7j/17CG0yqFHBJ/ZI5DG5b TXfLXvubjy/vsniG2uE6hRIsA2DuDJ2m6t+LANPZMMAkxZRCfsQ0XwizUDWeEvwwUVBV SaY+AckxwliHU9fOI1pIPitu8iXDGZnG7dZJQrLbz/utWwkSp2cKAlluzTIbGinge0EX wWk/I6ttU4UElPsEkThhFtsyZjPx88eGiN+Fz+o18TPvdvqC9H6c6C/W39gcldFOAzo4 75J+qby9juoo7QGTwP9MBDGbgY2v0zQagGAn33uZaVxE3kNZKY8A0bhb2EoxR6OZi6BT avqA== X-Gm-Message-State: AOAM531ajKv9h9jpV/koAg5dScYTwsQEvYPmhsCpCw2Xh/m+DS8u5kBt xDuFToj7R8X1k9FowQLQ+lQ= X-Google-Smtp-Source: ABdhPJwrlyOl/C5mF6YI5RoCgIA4G9pTJYIaIywNTdmGCl2pJCordfAtGGDq+i/IJSpT/Y3ql53nXg== X-Received: by 2002:aa7:cb09:0:b0:413:2be4:c9fa with SMTP id s9-20020aa7cb09000000b004132be4c9famr7771105edt.106.1646589094457; Sun, 06 Mar 2022 09:51:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:34 -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 20/26] usb: gadget: tegra-xudc: remove using list iterator after loop body as a ptr Date: Sun, 6 Mar 2022 18:50:28 +0100 Message-Id: <20220306175034.3084609-21-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 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/tegra-xudc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c index 43f1b0d461c1..7c39d8a9e49d 100644 --- a/drivers/usb/gadget/udc/tegra-xudc.c +++ b/drivers/usb/gadget/udc/tegra-xudc.c @@ -1413,18 +1413,20 @@ __tegra_xudc_ep_dequeue(struct tegra_xudc_ep *ep, struct tegra_xudc_request *req) { struct tegra_xudc *xudc = ep->xudc; - struct tegra_xudc_request *r; + struct tegra_xudc_request *r = NULL, *tmp; struct tegra_xudc_trb *deq_trb; bool busy, kick_queue = false; int ret = 0; /* Make sure the request is actually queued to this endpoint. */ - list_for_each_entry(r, &ep->queue, list) { - if (r == req) + list_for_each_entry(tmp, &ep->queue, list) { + if (tmp == req) { + r = tmp; break; + } } - if (r != req) + if (!r) return -EINVAL; /* Request hasn't been queued in the transfer ring yet. */ From patchwork Sun Mar 6 17:50:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549172 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 1ABDCC4332F for ; Sun, 6 Mar 2022 17:52:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232600AbiCFRxE (ORCPT ); Sun, 6 Mar 2022 12:53:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234098AbiCFRwm (ORCPT ); Sun, 6 Mar 2022 12:52:42 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F12F3EAA6; Sun, 6 Mar 2022 09:51:37 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id a8so27438916ejc.8; Sun, 06 Mar 2022 09:51:37 -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=MLBHYSaeD3eFzFQMOP5a1mgmC2xAZpNxSDfQ1U/Maqg=; b=X6Eiym0FGEc/Yg2lPaH7lAvq2l4n8uQyMYgQ5bQFCommhQHJy9m6qmVkseS5uNsqMa 3XfEX9CxwQPRbg2B4OkXWeqfC7zqF5m78NCSd6NpT+c0W+3XsV2A4zqZWtnfzw+o46L+ PQ49OmX4AzP1O3Iz8a9ZJT4XQMPamNRj2g/Ef5EBA6kID9Ng5/kokaZMVIe1DzZX/4EI yLdpMu0W/WHGXEJv8ENoQpSG8aP5IV6cLpD/43UTgj7uEEfkMu0dXApbWPPYr8gDSLQQ i2MN5eGCC6DH5OOnoS7wM8RaSYkXz9t1e+x5zSsP7L95PQJE0hDH8eqLZD8fh+3ZObWO luKg== 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=MLBHYSaeD3eFzFQMOP5a1mgmC2xAZpNxSDfQ1U/Maqg=; b=H6RNt3La/xOeBgSb/sMJhgZShbmB/PrNpdZHB8FSDds80Cp+ufO/KHtWrkDWJ5yjCt 39Sv0hZkK+9jUkVAbM5HCOe1AOAynTLCzW45OkXgy5ZoFkqZDbadX4Kh50SWYNAjCJ+M v53R29riuQ6ZwL0k+hW/6+dkpFNFiVCcOxlXth18/2uZQGZkCMPFDTr6VZ4EK0paOpv1 OcIGtB7yddUy2Cx1IxR4Vzfsfsut/2mYCILodNN7O9l4jZSSviI2wQbs7QDLZXJv85p+ MR0lljdiEPERP/3sHKxWqW+Mh/bjAVnYoeW5v+T4qZlO8ZMAXrCdAH4uxNENbkGqoAWm Edag== X-Gm-Message-State: AOAM530MdnkOuWTryXpu7jWW3ECtLZL0D/iFK6LtaSdDLYPNQaA8YjB3 5zgD9UCtCp/IJZKo0N58pRQ= X-Google-Smtp-Source: ABdhPJxDxPmdry9ej5ZNQ7R5EE2walSLSRO7ED+xafi0SIp4n09749RDjSh2oQFkuaZp+MS22p83FQ== X-Received: by 2002:a17:906:b052:b0:6ce:88a5:e42a with SMTP id bj18-20020a170906b05200b006ce88a5e42amr6562556ejb.237.1646589095739; Sun, 06 Mar 2022 09:51:35 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:35 -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 21/26] usb: gadget: composite: remove check of list iterator against head past the loop body Date: Sun, 6 Mar 2022 18:50:29 +0100 Message-Id: <20220306175034.3084609-22-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 When list_for_each_entry() completes the iteration over the whole list without breaking the loop, the iterator value will be a bogus pointer computed based on the head element. While it is safe to use the pointer to determine if it was computed based on the head element, either with list_entry_is_head() or &pos->member == head, using the iterator variable after the loop should be avoided. In preparation to limiting the scope of a list iterator to the list traversal loop, use a dedicated pointer to point to the found element [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/composite.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 9315313108c9..26908d012ac8 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -1690,6 +1690,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) u16 w_value = le16_to_cpu(ctrl->wValue); u16 w_length = le16_to_cpu(ctrl->wLength); struct usb_function *f = NULL; + struct usb_function *tmp; u8 endp; if (w_length > USB_COMP_EP0_BUFSIZ) { @@ -2046,12 +2047,12 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) if (!cdev->config) break; endp = ((w_index & 0x80) >> 3) | (w_index & 0x0f); - list_for_each_entry(f, &cdev->config->functions, list) { - if (test_bit(endp, f->endpoints)) + list_for_each_entry(tmp, &cdev->config->functions, list) { + if (test_bit(endp, tmp->endpoints)) { + f = tmp; break; + } } - if (&f->list == &cdev->config->functions) - f = NULL; break; } try_fun_setup: From patchwork Sun Mar 6 17:50:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548834 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 57355C433F5 for ; Sun, 6 Mar 2022 17:52:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234020AbiCFRwu (ORCPT ); Sun, 6 Mar 2022 12:52:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234119AbiCFRwo (ORCPT ); Sun, 6 Mar 2022 12:52:44 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93FF83EF32; Sun, 6 Mar 2022 09:51:38 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id f8so16969057edf.10; Sun, 06 Mar 2022 09:51:38 -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=XKTcpjYqRS4uQbtkHCNXnLN0vPC/RNRvwxWfOqD2TvU=; b=jToVGfKuRLRBrK4ZqfLgc2Zrod2uqO8U9qHRHHzSfQS1clzwMQUCqJ9guwSTqdVsy/ RaklZeqjcO4OrfixJae0WRU6WG8bqRqhxYCXhB8SKwceqBVE7cR7K1AaFyST7vIDIBtq WTZlPjX3jRjdX4ZOo1tT6tdYRTvFhn0IcbZI0AT8sFjka7A+/qw/jF/E6L3p94k/NHYG rKcUo/oRI3d7NgLwbPrpmQbWnC0DGHWf1I2p99YLbV4FVpiJLF/rYqzv6X4IwxczmHW2 yWa/KH3swYpneuO5o1AflJDAYxBq/TB+zrDwaEGQTg4T6DYjXJeIibFJ9rOPzyUs4v+9 eCGw== 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=XKTcpjYqRS4uQbtkHCNXnLN0vPC/RNRvwxWfOqD2TvU=; b=uwY+3ZqlAhOQJYWrAOs8qUm7i1VFc1j8MrawWTc8FUXaP+dbuZMxOzf78hjw0fdo5N zZc0qrKWuj082Kcy1XyMrtlrLpnoVvUQRoaEobHhjKKB/cSmpVx+k+MSqWZVoqd6cl5d GANruuI7WrCBraHpGA6UXXh9QMIylL2W2CNXjPkKGEK1ysTWNst2Oxjb3Fr0b51/WJZ8 u+sV+w8WSg0bbgDXZ2goc6cSNltfFWYiZyWZL/YtzBSbq9WCTA26Uv7yiEu5sxddkxG0 r0E95l2llwq3b6rDnTE2c0EVydLOfqA87j6foxUHz7EGr1e2Tf4vpvp+oTOm3DCoKOux dJHg== X-Gm-Message-State: AOAM530ioChE2mAxvD5ZJgfHhrltYfvqvY7ghCsktvz3WFbtGJ0GLTwG /H7FJd7h+8sHFCYiiNRnMe0= X-Google-Smtp-Source: ABdhPJz+oIZawQWxxP2050yuUydT5hnlPsXvNkl3GbdaPI80qnu1uIORJN5sMFPiAej3oTM6D/euOQ== X-Received: by 2002:aa7:d505:0:b0:415:9f06:d4f5 with SMTP id y5-20020aa7d505000000b004159f06d4f5mr7840371edq.305.1646589097019; Sun, 06 Mar 2022 09:51:37 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:36 -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 22/26] usb: gadget: pxa27x_udc: replace usage of rc to check if a list element was found Date: Sun, 6 Mar 2022 18:50:30 +0100 Message-Id: <20220306175034.3084609-23-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 To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable [1]. This removes the need to check the rc value to determine if the break/goto was hit and can be made more obvious by checking if the variable was set within the list traversal loop. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/pxa27x_udc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c index f4b7a2a3e711..eed793deeda0 100644 --- a/drivers/usb/gadget/udc/pxa27x_udc.c +++ b/drivers/usb/gadget/udc/pxa27x_udc.c @@ -1159,7 +1159,7 @@ static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct pxa_ep *ep; struct udc_usb_ep *udc_usb_ep; - struct pxa27x_request *req; + struct pxa27x_request *req = NULL, *tmp; unsigned long flags; int rc = -EINVAL; @@ -1173,15 +1173,16 @@ static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&ep->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; rc = 0; break; } } spin_unlock_irqrestore(&ep->lock, flags); - if (!rc) + if (req) req_done(ep, req, -ECONNRESET, NULL); return rc; } From patchwork Sun Mar 6 17:50:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549170 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 EAB32C433F5 for ; Sun, 6 Mar 2022 17:52:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232759AbiCFRxK (ORCPT ); Sun, 6 Mar 2022 12:53:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234129AbiCFRwq (ORCPT ); Sun, 6 Mar 2022 12:52:46 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D90AD54BEB; Sun, 6 Mar 2022 09:51:39 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id yy13so18613264ejb.2; Sun, 06 Mar 2022 09:51:39 -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=zn5EzvNdFkkfq9WLeKE8vnjWGv8x8y/sNNvXHm8oKGY=; b=CibBxlAmJ+b26tsYTln2yODIK63moPUKBg4ThtwpcCVTkYbiGYvteUI4hjDr/ZILBd 5V8FzlHyysBxSBVejJif9uF53N50M69JZH8UJP6Nfqjcto+8qkRpKoO3JZL5qhJoVZwu QcPM1uprJtw7VigiwDFrt0Hf7EaegTMcXMOAZDSv8wLRZvEXbAsMcxY6kAtL/ghXvPS+ 8FLmhGhVM3JF4DYdGOHF//Eq8X0nnLtbxaqZkpulpa3LFwqQKuWmWncmLfofoU9DOPhe 0yw62fUb6Bu22Y91COkYc6CEjilGXRxZ6VZVbyPURaNRpBObRNOTcXim5OLmoZ1lm6ww B5vw== 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=zn5EzvNdFkkfq9WLeKE8vnjWGv8x8y/sNNvXHm8oKGY=; b=vzA4RIs709JdhazHoELc7nkVF5bG3DF0Xc18RsbeLgCq5jqJRVGfetfITr7tdysd8a /25bH6ir5N8sKn7dg70NMeIN3JFBM+f1SLtxxkIN6u3Qdeaj4FEkqeEEVgHneadDXoqN 6yjO/uEcC1Fb9X8QOf81gp+ddyWfQpyN9+vONNSP4gWd6JyNB/3CkK2d2ogpm1+E0dYX Oi14YxlxBs11xdZ/o61+jF9VJnuvMAkJfH7f4hoG9+o0vvp6XrwR9vY4ffVku9KZpey6 UAzpcETpdSLO7iFmZi/N72w/6o8tWQux4PWu7VMiaG9InKALDQozmjoJWEmSPESb9lEw AQZA== X-Gm-Message-State: AOAM533RqfiN0lKGEYNmmcFQPcKW1ERjizmOaGPJr+/Ch//gMsUyMYSm IY0mMn6FLvgyP99neu8cLlQ= X-Google-Smtp-Source: ABdhPJyEUmbzavFxuxNs5CE9PEv2BMQu0+VKX+xGhrNN14rjmWPymqB7BsY86nqd/5KkzLfH4r9ydA== X-Received: by 2002:a17:906:4cd2:b0:6c8:7a90:9c7 with SMTP id q18-20020a1709064cd200b006c87a9009c7mr6466344ejt.439.1646589098341; Sun, 06 Mar 2022 09:51:38 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:37 -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 23/26] usb: gadget: udc: s3c2410: replace usage of rc to check if a list element was found Date: Sun, 6 Mar 2022 18:50:31 +0100 Message-Id: <20220306175034.3084609-24-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 To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable [1]. This removes the need to check the rc value to determine if the break/goto was hit and can be made more obvious by checking if the variable was set within the list traversal loop. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/composite.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 26908d012ac8..fa9f4aedf52d 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -863,14 +863,14 @@ static int set_config(struct usb_composite_dev *cdev, const struct usb_ctrlrequest *ctrl, unsigned number) { struct usb_gadget *gadget = cdev->gadget; - struct usb_configuration *c = NULL; + struct usb_configuration *c = NULL, *iter; int result = -EINVAL; unsigned power = gadget_is_otg(gadget) ? 8 : 100; int tmp; if (number) { - list_for_each_entry(c, &cdev->configs, list) { - if (c->bConfigurationValue == number) { + list_for_each_entry(iter, &cdev->configs, list) { + if (iter->bConfigurationValue == number) { /* * We disable the FDs of the previous * configuration only if the new configuration @@ -878,11 +878,12 @@ static int set_config(struct usb_composite_dev *cdev, */ if (cdev->config) reset_config(cdev); + c = iter; result = 0; break; } } - if (result < 0) + if (!c) goto done; } else { /* Zero configuration value - need to reset the config */ if (cdev->config) From patchwork Sun Mar 6 17:50:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549171 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 98D43C4332F for ; Sun, 6 Mar 2022 17:52:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234023AbiCFRxH (ORCPT ); Sun, 6 Mar 2022 12:53:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234076AbiCFRwt (ORCPT ); Sun, 6 Mar 2022 12:52:49 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 624BB5DA46; Sun, 6 Mar 2022 09:51:41 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id qt6so27421502ejb.11; Sun, 06 Mar 2022 09:51:41 -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=Mabw6oo0UExXVw3UKbG1p1cOpksqyZA3+XNF2Z0ESy0=; b=Sj5WgvjVNGKGioDvkwEfdSxzknyIiisqz6LNams662IbPPPpzFVO3pBtK1+GOAO37l OFiGhAWIjmz1Tf717cO1p9miIL+PB3rp4alrNokui1CGX3/nJ/36VUxfv+X4C4DfO8Wp hgkYVde0YzBh0ru4Rz4yvU5h7rmYF0+CRyMpcpfWuYEmLdofFcD77E7I1gAxRti5bFt9 WHm1Dz6hdklJQ8/AdPB9OZqS3VmIafvIpx6vJvPYafq5/08ywEqI5uPyMZ0YKk1Bsnwv M1jEUfDOI5I6rIaHI0pTLAbeni4JtGGS9o1LRIfwO4LwryhsPyoM8AkyK3SAGLaoTS+j 8wqA== 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=Mabw6oo0UExXVw3UKbG1p1cOpksqyZA3+XNF2Z0ESy0=; b=SESvHTF9K4EXfJWrWqxdofXGd+bNsQyrBbY17LOlOzKSsZErz4IblOseOHqpesKBTR aQSvjcnHNPEG/UDcOay+XklpoVH7Y07F84mJBDyEyJa/xeTqJTYEVHWk7HUw2a7OGto0 5TsNwWPAtV9hSAzLCFzbvp0q4GWvHNeXKCVLlRh8oA2HG+Q/drJf8RxbrFpp3VOLZwvs n7CmjHYi8leyV9aNZQpY6VnCBMPmA7wZzDAhQDXxcTmwOLfCPEbrZygf8+5KWbrMXDl7 D+QX5Q25DNVWGNPtua64XOkKGECMYoJI9yRiRV7tTorHVMgftjAamMz17rWNk+ej7J4U ZNCw== X-Gm-Message-State: AOAM530Q10UVgVgHJ66r8XMAMl/IGRz8bJ/+oKuUmCvwVz0EXmzIH3k6 6TLrugBr3DM7ByC+xw44nPs= X-Google-Smtp-Source: ABdhPJwHiCsF874nALTnLvOsZlmaSBwgAGtg0Nx9+1Eu9B5wfvuj0173uoVehKdX38U4l5Kw3rikUQ== X-Received: by 2002:a17:907:a40f:b0:6d7:9f56:b511 with SMTP id sg15-20020a170907a40f00b006d79f56b511mr6476006ejc.674.1646589099630; Sun, 06 Mar 2022 09:51:39 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:39 -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 24/26] usb: gadget: udc: core: replace usage of rc to check if a list element was found Date: Sun, 6 Mar 2022 18:50:32 +0100 Message-Id: <20220306175034.3084609-25-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 To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable [1]. This removes the need to check the rc value to determine if the break/goto was hit and can be made more obvious by checking if the variable was set within the list traversal loop. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/core.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index 568534a0d17c..d3c269ce3851 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1528,7 +1528,7 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri int usb_gadget_probe_driver(struct usb_gadget_driver *driver) { - struct usb_udc *udc = NULL; + struct usb_udc *udc = NULL, *tmp; int ret = -ENODEV; if (!driver || !driver->bind || !driver->setup) @@ -1536,10 +1536,12 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver) mutex_lock(&udc_lock); if (driver->udc_name) { - list_for_each_entry(udc, &udc_list, list) { - ret = strcmp(driver->udc_name, dev_name(&udc->dev)); - if (!ret) + list_for_each_entry(tmp, &udc_list, list) { + ret = strcmp(driver->udc_name, dev_name(&tmp->dev)); + if (!ret) { + udc = tmp; break; + } } if (ret) ret = -ENODEV; @@ -1548,10 +1550,12 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver) else goto found; } else { - list_for_each_entry(udc, &udc_list, list) { + list_for_each_entry(tmp, &udc_list, list) { /* For now we take the first one */ - if (!udc->driver) + if (!tmp->driver) { + udc = tmp; goto found; + } } } From patchwork Sun Mar 6 17:50:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548832 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 1BE63C433EF for ; Sun, 6 Mar 2022 17:52:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234053AbiCFRxI (ORCPT ); Sun, 6 Mar 2022 12:53:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234138AbiCFRww (ORCPT ); Sun, 6 Mar 2022 12:52:52 -0500 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BA864090E; Sun, 6 Mar 2022 09:51:44 -0800 (PST) Received: by mail-ej1-x629.google.com with SMTP id kt27so27577422ejb.0; Sun, 06 Mar 2022 09:51:44 -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=6nL7RfWQJUoD4Uxzup8Ya34s2l2dL8vEBMEWVZsq5Ao=; b=S+XeJpGyyiU19cam3cKA+JBLCqcrL6ui9Npkw6EC9KPEfYQ3WAQ9Ct1vo8chBsN8yb iU1XEJbGYEuq1O0PlZ+KNAjNzRCWvLpBSTW3N6IzbNLQNd1OTNHbgZxxilk5uGbl+nqs ZLIbP8a0H8nnMjKCFWGkAWVBc4EfGmYEySJFOR1wAeIrrv+lhqaJu29S/bkVLqWAqgTi 6cw3qo+RLDDRmgnSbQhj5bUYjGPkBOhCmGdQUKY9nNZCl29i1jmSvwfPhKg6yB1K5RWi wdqJgU0G/ENcI3zYGRCT5z45pJBXnuEauCfZvtJ65//xFdxg2yYvJx2cA1BNHJFXZABs qxBA== 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=6nL7RfWQJUoD4Uxzup8Ya34s2l2dL8vEBMEWVZsq5Ao=; b=UEkIfmIJdMmRxXevBK+6WpugHZ8x8zQL3H2sUS3Stsi75GsrglZVH1FAhCyfVKhrFy oNYFCe2Q6YDAot63fdDsSwmKoEaHE+aU9uhjEEyZBzAFdQRC3x1dNF+mhX6mNIyTbsCN E1BBMoOQsDsWz2VwQLPNcCKrqy+RRlBKRrtA+WWGviVfWNsPW+REAmOEwZhkQXC8H+iV UvfNofkh2YLYV+bdVv/4gLUwT6zCUMqqyUJ+hcjW+rOfcjTn1QZ56Tf95SMPfz9adfJd d8eJkhQhfNIm4OGZm2EmcVe0Nqm29++HcQ0OLw33Bmb4y8+7FFTCIuknytCHYKnRp2Fl 7h6A== X-Gm-Message-State: AOAM530EsoBW8mIhqae3XxSswoPeOw0j2STS+MHP1RnI/Z1HkD5Xnl61 FLq/NvXOawlp5Gfy6R/Pun0= X-Google-Smtp-Source: ABdhPJxOmOH2jyWx2isFpTEsJYGn2fFofs/tdGmKq2C/AcUm2ZFI8lfEcJptT7RCZHzFu4wV6Pi1lA== X-Received: by 2002:a17:906:7751:b0:6ce:e3c:81a6 with SMTP id o17-20020a170906775100b006ce0e3c81a6mr6271973ejn.278.1646589100841; Sun, 06 Mar 2022 09:51:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:40 -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 25/26] usb: gadget: dummy_hcd: replace usage of rc to check if a list element was found Date: Sun, 6 Mar 2022 18:50:33 +0100 Message-Id: <20220306175034.3084609-26-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 To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable [1]. This removes the need to check the rc value to determine if the break/goto was hit and can be made more obvious by checking if the variable was set within the list traversal loop. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/dummy_hcd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c index a2d956af42a2..f21944707707 100644 --- a/drivers/usb/gadget/udc/dummy_hcd.c +++ b/drivers/usb/gadget/udc/dummy_hcd.c @@ -751,7 +751,7 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req) struct dummy *dum; int retval = -EINVAL; unsigned long flags; - struct dummy_request *req = NULL; + struct dummy_request *req = NULL, *tmp; if (!_ep || !_req) return retval; @@ -763,17 +763,18 @@ static int dummy_dequeue(struct usb_ep *_ep, struct usb_request *_req) local_irq_save(flags); spin_lock(&dum->lock); - list_for_each_entry(req, &ep->queue, queue) { - if (&req->req == _req) { - list_del_init(&req->queue); + list_for_each_entry(tmp, &ep->queue, queue) { + if (&tmp->req == _req) { + list_del_init(&tmp->queue); _req->status = -ECONNRESET; + req = tmp; retval = 0; break; } } spin_unlock(&dum->lock); - if (retval == 0) { + if (req) { dev_dbg(udc_dev(dum), "dequeued req %p from %s, len %d buf %p\n", req, _ep->name, _req->length, _req->buf); From patchwork Sun Mar 6 17:50:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 548831 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 AAA92C433F5 for ; Sun, 6 Mar 2022 17:53:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232454AbiCFRxz (ORCPT ); Sun, 6 Mar 2022 12:53:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234198AbiCFRw7 (ORCPT ); Sun, 6 Mar 2022 12:52:59 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5F053EF30; Sun, 6 Mar 2022 09:51:50 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id bi12so14345023ejb.3; Sun, 06 Mar 2022 09:51:50 -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=HcQZB6Ou2DJOpmDHHbEeLT9eVra9fyNzoo1Isgk0YuU=; b=G31UKxrXM0ceKXWQOtiF6wqKmSQfZ83nhi589fq6DGgiMF0n9ZjeLl0ryCQoijQWhZ ap6sQT6lAHkedMcbN/K/WLzVuF5S3JxkLhxnN/YkzZ4roTQRGmRChY7WvCci8/UfjCKP xMqmv80JZZBQkj0D9FhL/nsjA063Bb+aL4M640Cn0TEwlzFBDWJnmHUcIb1Qv3FN65VB CS93zKq4467GNhU81fFb5IqDD6iCQjONnEJL9MPiP/EDQR7YNz1O9vrRlhUGY+qCLvi7 xrDlfLPQCjAR4ijT1aianHXk5XNVJTmO5oIU336kyiGQPheymeOqJjBFcJHQxxgO1BPz 0mwg== 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=HcQZB6Ou2DJOpmDHHbEeLT9eVra9fyNzoo1Isgk0YuU=; b=TrNI0CQVImFV1iFpgjNCrSG6yjRHbQujyGuSeWZGSx1Hi5CElJkVyg4kGj4G5lTtFc rGeOuL3nh3+9Kbp6qMkQzQhVr+Pi3J6QzxdjgqNzbvj5eMndeQmTKzw/FVxeOfo6rDoN 5T1D82Wu+J3Hc+71Lf8mScNWSyr+WVcRdlDLqByDrH8Cp/ADwexXd+SkfJsCd3tmSX0p PfzRPOaen+Q8XJVMV27NrGlz5gYImu8StjxvuMyeaFfM4wG7lr1mR91aACcZQbmRPLbw uRey46S5FofKotwuO27lkOOOgJH4dzFeMfOUmbrNjbWREVAF4L5aWQJFPGoy7QD/5e4P gNTg== X-Gm-Message-State: AOAM532NJ7Q7kQPQQDVmmgM67NcpMg3KXWjw7ZgfTJD0+ZaPcDyKJvv7 k/ueJBwAtyjoiw1VnxnVHYA= X-Google-Smtp-Source: ABdhPJzIYgztiVm79b+tYLDse5ioBPvmL8FWLZSMdXXTiwy7PDaN42gD7M5HGDOIE0iwmdYSgsWvtw== X-Received: by 2002:a17:907:1c20:b0:6da:8a7f:657 with SMTP id nc32-20020a1709071c2000b006da8a7f0657mr6640896ejc.730.1646589102253; Sun, 06 Mar 2022 09:51:42 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:51:41 -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 26/26] usb: gadget: udc: s3c2410: replace usage of rc to check if a list element was found Date: Sun, 6 Mar 2022 18:50:34 +0100 Message-Id: <20220306175034.3084609-27-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 To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable [1]. This removes the need to check the rc value to determine if the break/goto was hit and can be made more obvious by checking if the variable was set within the list traversal loop. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel Reviewed-by: Krzysztof Kozlowski --- drivers/usb/gadget/udc/s3c2410_udc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c b/drivers/usb/gadget/udc/s3c2410_udc.c index e3931da24277..fe6ecb0d16d1 100644 --- a/drivers/usb/gadget/udc/s3c2410_udc.c +++ b/drivers/usb/gadget/udc/s3c2410_udc.c @@ -1265,7 +1265,7 @@ static int s3c2410_udc_dequeue(struct usb_ep *_ep, struct usb_request *_req) struct s3c2410_ep *ep = to_s3c2410_ep(_ep); int retval = -EINVAL; unsigned long flags; - struct s3c2410_request *req = NULL; + struct s3c2410_request *req = NULL, *tmp; dprintk(DEBUG_VERBOSE, "%s(%p,%p)\n", __func__, _ep, _req); @@ -1277,16 +1277,17 @@ static int s3c2410_udc_dequeue(struct usb_ep *_ep, struct usb_request *_req) local_irq_save(flags); - list_for_each_entry(req, &ep->queue, queue) { - if (&req->req == _req) { - list_del_init(&req->queue); + list_for_each_entry(tmp, &ep->queue, queue) { + if (&tmp->req == _req) { + list_del_init(&tmp->queue); _req->status = -ECONNRESET; + req = tmp; retval = 0; break; } } - if (retval == 0) { + if (req) { dprintk(DEBUG_VERBOSE, "dequeued req %p from %s, len %d buf %p\n", req, _ep->name, _req->length, _req->buf);