From patchwork Tue Mar 8 17:17:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550061 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 6D45EC433FE for ; Tue, 8 Mar 2022 17:19:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349005AbiCHRUn (ORCPT ); Tue, 8 Mar 2022 12:20:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348901AbiCHRUU (ORCPT ); Tue, 8 Mar 2022 12:20:20 -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 2E2F653E1C; Tue, 8 Mar 2022 09:19:08 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id gb39so40697946ejc.1; Tue, 08 Mar 2022 09:19:08 -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=wkWk+pJBOAzTyRQTmBb712+gQyHq/pA4s9cAlOSRA8E=; b=PGCNMcLMI62MHZBGcmL1CRySCL3E80fhSQcmm570QvuEOjBOK7zBv9VtYr4hEpxNq0 qCAiPDLZ1W2scA39q/4BXOyNk/f+rc0vInBGsDts9ftfs0jHfyxk6lnsJUU9WA/nmfYe 9hMkkTTv6Jr7AV852g+ov8HLeaZbGAizdSN2XiOdN6cfUlWYC9QoQIYdK+t6o74wY1Kz CAqsdr8WXA3CDaYefVVxpFTQfz5k9IxbXU3Hccb3pnhAO73izhjqEF73t1bzso1C649z 55jhLcQyxctDXRTfGHJxapyhhUzWeYZ2jB5t6qhYhTd6grcEZm6/vrEb9XyFatgooNJd x6xg== 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=wkWk+pJBOAzTyRQTmBb712+gQyHq/pA4s9cAlOSRA8E=; b=3UQDc0pHeBBzEo7oUFUwYTPmW9pNbm+YJlDDXb0t8FOWvw4kcxZM9nM8XS6QU9QYP6 bcdiF6ksmAZGVgPRwgRAQ24HcEW0U7KUm1r5gujSUFnECiC1XBWMLtp5j6bzKu7TvY0/ lMBUjhEqr70dhzzpmss6lnW6GmMZHW7gC+ws+Mp/h7nJrRLoFDMzorVpA2Fp0LP0KAVQ /lPg/U0Zgo63M1pl8Jrt9NlLMqNXlWVUS3i3jZK1KKtRYxl4jM+3lONHkGKprPSKufx4 9N+MMuCdCblToOjOtrD5Awb5cEsq74jxNoh6Rk48h2OUmzRiZmSegfPrztGNAY29I53S VVMA== X-Gm-Message-State: AOAM533isHXQGSPRkHZAyeQEgR7S/emZLbyyubJS/LyOsEmeEmOmXoM+ RDhsw0hOUCePayX/fD6U1NA= X-Google-Smtp-Source: ABdhPJwjd15xQrk2r0RtEosI5eNq0bUkl2GLZ4+qkb9+rHvJjGw5YP/fVseF5ysgEMd8FexKkfauuQ== X-Received: by 2002:a17:907:2d11:b0:6da:924b:748f with SMTP id gs17-20020a1709072d1100b006da924b748fmr13875456ejc.584.1646759946545; Tue, 08 Mar 2022 09:19:06 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:06 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 01/26] usb: gadget: fsl: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:53 +0100 Message-Id: <20220308171818.384491-2-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/fsl_qe_udc.c | 13 ++++++++----- drivers/usb/gadget/udc/fsl_udc_core.c | 13 ++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/usb/gadget/udc/fsl_qe_udc.c b/drivers/usb/gadget/udc/fsl_qe_udc.c index 15db7a3868fe..d80a7fe5ff62 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 *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue + req = iter; + 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..50435e804118 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 *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { ret = -EINVAL; goto out; } From patchwork Tue Mar 8 17:17:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549655 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 34E2DC433EF for ; Tue, 8 Mar 2022 17:19:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348929AbiCHRUc (ORCPT ); Tue, 8 Mar 2022 12:20:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348891AbiCHRU0 (ORCPT ); Tue, 8 Mar 2022 12:20:26 -0500 Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F85554196; Tue, 8 Mar 2022 09:19:09 -0800 (PST) Received: by mail-ed1-x536.google.com with SMTP id h13so13272650ede.5; Tue, 08 Mar 2022 09:19:09 -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=NKBqq8H8G0r7u4YOEB6Uo0ujE9phZkj1yTyESdTdeCM=; b=ZFc9SayGmZuwBLkbiqoy2iDFk5f3qgEhdtJj3Dv7GHS2ypdaZTjxauZ+hlp0trYtJa 6M4QEG5riT1if7unqpPROovPT4iZy7DxsyzKiO2keZ0zP9SCUfH7za56UNf4yhEYiR1W Zv+nf4lMjwR3fkHJjnmEWcK2WW460qfUBwPOMjkzv3eCkyDQyykoDbItDltUuRcTwrJr pG4CP1bXQLDtWdHmUqjSgKORnsAbOU39eGOAbT2p8g3172LnhTr91WyaVlTWNbKBB2zn NIRM0BhkmF4hLKwhkuY7VdmK0q5FKA7xmA8wUQfGsEiCXrWBclx4AShbCuvx1pPHky0J VNgw== 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=NKBqq8H8G0r7u4YOEB6Uo0ujE9phZkj1yTyESdTdeCM=; b=CWBilmSslu5Oi2bneCx+AoGqfJSYyp8V7Lf/icZlvFCqEJhe8083qF0+zt99X8tnHo 52GUpid3dd8RrMX+L+ZydDd3ZsqvdHopharXixVHwCO7C8g9ij0Ehp1JC7qQZtwG8qD7 VEOftuHA8tBw8jmXUl1gXkvHz8/qcXkUXPy5AFXd77accdXNlJorPMZvZcoRrtyN4X0D HRTsh2hvPpXnQ6AOXBrjh9vJ2tLhONjHQQk3JyQuwkruYOnwyLfH1QZkMqcp6M6s+FL/ gh/FAENHMhziuBDTM4r5qVYkP1THtvFVLxJiGjaJAjTQEdKfrMwcPqMXWZpetNtfTZvS lGng== X-Gm-Message-State: AOAM530SPcdggP13rsXv/yvz2e8xryZgKd9OZUzkkCwJ5Jb41bbUEmnB PlRvzLoiMBHrR0SqsLq0vZU= X-Google-Smtp-Source: ABdhPJyM1gC52QuGTeL8TtyGBMOIEOKlyECvrtuFR/2dTrbGjWxPBGFVVbIaUboCG3sJrNF8ZedJPg== X-Received: by 2002:a05:6402:40c4:b0:416:3e66:1825 with SMTP id z4-20020a05640240c400b004163e661825mr12232139edb.284.1646759947785; Tue, 08 Mar 2022 09:19:07 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:07 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 02/26] usb: gadget: bdc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:54 +0100 Message-Id: <20220308171818.384491-3-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/bdc/bdc_ep.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c b/drivers/usb/gadget/udc/bdc/bdc_ep.c index 8e2f20b12519..fa88f210ecd5 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 *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->usb_req != _req) + continue; + req = iter; + 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 Tue Mar 8 17:17:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549653 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 573D6C433F5 for ; Tue, 8 Mar 2022 17:19:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232319AbiCHRUm (ORCPT ); Tue, 8 Mar 2022 12:20:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348947AbiCHRUU (ORCPT ); Tue, 8 Mar 2022 12:20:20 -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 A019C53B46; Tue, 8 Mar 2022 09:19:10 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id c20so6975882edr.8; Tue, 08 Mar 2022 09:19:10 -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=FiQ4puCFE77hcY5XsHWeEmKJVjDUyRyfQhSidRFLY4Y=; b=l0epHchFHciZJxsva8RSY8pNQ3WDGf/eZd1iy9Mq/XLOv+t96W3/QtX9vtGfgB/dCB W6w+V023vcKsjpn3UUO3VAIHmSgwpNv1jD9KR7BYD4H3KvRijf8TdUUrkFCxE8tkxKfD Cwd/q8dKe/y2W3MESJbRiaKly6OMLZsCDHV6i1KoUgEnuicD9SGghZFPZpS3QaNCgTpH eKQkvJyjAp+x4y+XrAPXRrooT94BRIM8gpw2W/CZtE/K8poXB2+5RWW5SHGPpV41DZAT hZZOxOywa4ggoLqriGpFYAIRvIAIVrPl9TzToEDd6c9EYGJOnjHj2m3vwhZTU1qdlbLp UgWw== 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=FiQ4puCFE77hcY5XsHWeEmKJVjDUyRyfQhSidRFLY4Y=; b=o7zmSAehNbj5sj5rUqsJHO7P/KwkAH6mcMnJaYpq1HTWytstboIYqwl/PoCj9C1DCX +lvoAc7ipb5H33XVvVbEQinecLNrod/fdgp+1U8/rwcIu71WYXTlNZSiZppJGSjVJ2Rn 0NlHnNjcou/omODk21wjkztnMCLZN89FmD9OnoOB39t4CdDewye3I5rzexyscDTRstfY HkMagGcL+w8tuNDtNU7KwHHxZqHsL3OoXjo1FbfdxORVh1HanXpbPImGgMqzSUGf7LMz PACGbmMC00rqLdwUb7QlT2pn+Pi9lZ4p88+H4ZAKOJMKqfqEZzE0zg8oVJ0ItMkpRDo/ oMng== X-Gm-Message-State: AOAM532mzrq+v8K3BwXfXIxw2soLeUGYJkcmP0ILhVkETrnYl1nqETdo R2HwtFXNYYwMNPK98F3ZAG4= X-Google-Smtp-Source: ABdhPJxY1GhaUsaCfE9od8zH2PGgh7xkgQrxbcExL3lAvQP4sM7TRLEFzzpGkqPP2VhjcBhAGqohbw== X-Received: by 2002:a05:6402:37a:b0:415:9501:e112 with SMTP id s26-20020a056402037a00b004159501e112mr17432359edw.402.1646759949139; Tue, 08 Mar 2022 09:19:09 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:08 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 03/26] usb: gadget: udc: atmel: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:55 +0100 Message-Id: <20220308171818.384491-4-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/atmel_usba_udc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index 2b893bceea45..ae2bfbac603e 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 *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { spin_unlock_irqrestore(&udc->lock, flags); return -EINVAL; } From patchwork Tue Mar 8 17:17:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550062 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 D2C0AC4332F for ; Tue, 8 Mar 2022 17:19:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348936AbiCHRUl (ORCPT ); Tue, 8 Mar 2022 12:20:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348952AbiCHRU0 (ORCPT ); Tue, 8 Mar 2022 12:20: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 C25AE541A9; Tue, 8 Mar 2022 09:19:11 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id dr20so40692814ejc.6; Tue, 08 Mar 2022 09:19:11 -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=jnMNicDFLPFYIm4a2kBPICTpJsAe2MnYZ9lJwoywQGA=; b=GaQjF3wqn4GDvugYvXEA1XjE+wgTl5NlMnFteV0S7o8N7s5d9UTG+9G5jeFiOMnWkT RskkhtsXFNvk1/H3WcrOojKAhWAwh7HglW+3DJjyy5rNrV7Po/lXl9X6ROJmiORWzN11 xL9h3DFcuURGNiGngica/PJxipY5z5BlDfcX3q/jxcka8ynC80NjVV0MwUWLEr1K1tGX iCS3j6syn+9+Uw4wIM5ljO+L9Nyu++x96ttz0xHnB19nsgROSsJE4gyQGDYgLLYCtb6X qohOA1Z0xzQLO/lV79wzNO9B6Yz6Tyyc8rtIVTUE9ga87i7C2gcvhGaCsbd3r5+R1895 WZFQ== 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=jnMNicDFLPFYIm4a2kBPICTpJsAe2MnYZ9lJwoywQGA=; b=TCiC7njCJWlvOMFnXe2/uLjW3EiNzBnh2l8uUAc7zdB/OG1xYy82paT+22vp2DZ7HF w2GOQJpT4YeV8BDpCFQgB7w3Ykz6oL9lWaPhcSTWL5QfL0Q9NwFm+rUA4iNC9LIQGb5A gSIKbUjILqzR4/06hzTfr+EMUMz4/L1vAGbtCbZG2Pb90WYCqrLo31f6YSwuzMmJZ+wK 8rtIXPSw3gp1xRT9PoxcluXHNknbWRU0k+qqNkgvnKYMKnRSKLMi6l61xp6CJZ7gQ3XA U1nGPfib5H8mpwGpLJF1zn519w7RAnw9kyMbtC74uGLUa5T+Lbz4dDrfNOHu34ys2buI nzfg== X-Gm-Message-State: AOAM533F4t5Vi6dGbM99QFf+jxA0xOICcGeoGl3V4NE3F+5Uo7Z+xFp0 4Nqj+x9vb8RiXYOLwBu1qmw= X-Google-Smtp-Source: ABdhPJw15Ja5rX4M5jLmfuwddHWLBmlT9d5NTtLN1JZhmh7XvUj+FntdT2S5+9Vf7v06LvsGfvzMvw== X-Received: by 2002:a17:907:168a:b0:6da:9167:47dc with SMTP id hc10-20020a170907168a00b006da916747dcmr14225921ejc.126.1646759950264; Tue, 08 Mar 2022 09:19:10 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:09 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 04/26] usb: gadget: udc: pxa25x: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:56 +0100 Message-Id: <20220308171818.384491-5-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/pxa25x_udc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/pxa25x_udc.c b/drivers/usb/gadget/udc/pxa25x_udc.c index b38747fd3bb0..6c414c99d01c 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 *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { local_irq_restore(flags); return -EINVAL; } From patchwork Tue Mar 8 17:17:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550063 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 C9713C433F5 for ; Tue, 8 Mar 2022 17:19:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348980AbiCHRUf (ORCPT ); Tue, 8 Mar 2022 12:20:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348956AbiCHRU0 (ORCPT ); Tue, 8 Mar 2022 12:20:26 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F34AA53E29; Tue, 8 Mar 2022 09:19:12 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id hw13so40605536ejc.9; Tue, 08 Mar 2022 09:19: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=GqEmTO3TB/BaMOOEvwW8TYss8zdrlc684GqD43um0jA=; b=MknBCaYjNSx5FjYohsB3V90sOa3skz8+dy14c7CqGtA0tEwwZ5wvIXZCgeqE/IX3oB kA7xE3rPUlO7N5R6W+PkqTISltnbRLdNlbIjMLt6VdsIja2Q44JuObhb5z6Nv2YEbxg1 XzntsZkh2QKOsh209A5T2OmhgGhg8ClpEzGT4uW7aRkrQYhl2b5yWNRaCmP51EWmBr3e kgeNKfjGIiP2ghbFMrBymVM7L3Xuk4ARC1aOlEPSHM5v7mEuTHP2KAHcik1lxoo9z+p7 dCFMFv3VNf4xBHyWAPZAJAPV6BpbEefpFvnEmU3Zi1x/yrKnYm52EB+EqaERzOUkqKXz YH/Q== 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=GqEmTO3TB/BaMOOEvwW8TYss8zdrlc684GqD43um0jA=; b=usDZ637vQNIvLuKBBmW+SiKyBbi+MyjWsM3GCBR1AF9JBJOSILNHXLs0AWreIf8NRu 2cZrdkrl2LQGBrdyLGQnRd+OJAqAVQz0+W247dedg32OV3arml61RjF9GBvuxF4vnPJs UNPm28Whtv2eF/s++rZUYL/8QkesAzbiApmE2A4LbVCuEDzRTGP/goq7D/aMYOp4OgVw UVkuUDuzS2tPOaqQ8MXDH1sR/ryNGnSdwXkiWVAabyFQgQUZE/PHKlYN2iGS/Dxp2W7k 1RHNlxBzYJt8eqIqoGd/H3Mc2aSwG5mQhTfk84xeTwxx0cL+sBK3ozH67etpMvi2hWjP 3lbA== X-Gm-Message-State: AOAM531wdTbPHfL7QOuMLRfxvLBpHQwSOOu9z9T1MmOHYth52HeKkwc0 vJlnVmyS8fCrjlUXi/D+vKM= X-Google-Smtp-Source: ABdhPJxgM4gBfD97zrZlv2Pm7LeoIlsoIGLLsBJYwEZqxJ/VlYoDNnA7PvugfvnWnpvIYyhnapSYBw== X-Received: by 2002:a17:907:6d0e:b0:6d7:c85:5bf5 with SMTP id sa14-20020a1709076d0e00b006d70c855bf5mr14212710ejc.31.1646759951355; Tue, 08 Mar 2022 09:19:11 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 05/26] usb: gadget: udc: at91: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:57 +0100 Message-Id: <20220308171818.384491-6-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/at91_udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/at91_udc.c b/drivers/usb/gadget/udc/at91_udc.c index 9040a0561466..728987280373 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, *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { spin_unlock_irqrestore(&udc->lock, flags); return -EINVAL; } From patchwork Tue Mar 8 17:17:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549654 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 AFCFBC433FE for ; Tue, 8 Mar 2022 17:19:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348942AbiCHRUi (ORCPT ); Tue, 8 Mar 2022 12:20:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348903AbiCHRU0 (ORCPT ); Tue, 8 Mar 2022 12:20:26 -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 2D18E53720; Tue, 8 Mar 2022 09:19:14 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id qa43so40691594ejc.12; Tue, 08 Mar 2022 09:19: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=DV/4uUkufHdigictOlTI0wPqj6AP/gAmirkywlppX9w=; b=R8ehEfpBbpb8D/RDxqYFEbDZpSJlJ34xGqApi+5PiMot+aaln0rnNVyyMpwDKc35HS xLKLKMqfhb36/qmIqHSpicU2bVGOtUuf8fdi0XjoRHfL+fHQVyf153yQYzXwt2pE0bk3 1CoXoiN/SlIYYSLqZT7rkgVxV9Xx0IW+63M94wYfmr+6wYaBO9UgZxBbyju6tOv6WLcG SEaQC2HCFUeyPe3r2xTtcAnF+ISDQskzF0TT8Ur8xwScacndqA3uO3MfRm5Gd3Jp5fAV BO5zTlXswnx+0NrAKlVIRfsQd/7+Z0zJFfw+FrRSkpLSeZo16/MRgakrERc3wHvI6dvQ 8j2Q== 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=DV/4uUkufHdigictOlTI0wPqj6AP/gAmirkywlppX9w=; b=XG/ek/XxwHSbX/7eui8PPzVDY6vMRC77BWT4vNvEzrZwuXaQ7AupQtvmNmr1usqzdz lwvQJS3MjMdZQVivVtmsSss+Mqb1p4OomfbUGoU6tnG8EbpiFHO5tkMtszVJ3blWQjWh HnDj8ERCxWSzvRJWslQddhnJiarRB8fgX0KwgSBpffFna4eQXM8/bX4YXHY+6UFjN+3N TMZgcTz0zVd+RT7S2Ytym0zoN8vl+TFg2m7Hxdb6wZoNVzXXKI4G9NIEmc28jKIl3RNW M0RGvxIODB7AoCMES+bhe2W6H99xaisqUGoM/VvFCeeYrt42piceolOPUJbIG4INKX34 sFtg== X-Gm-Message-State: AOAM533Vw3huapdIM0O2IgAnRs0Zei95TyHig0r4ykMrLqYQmOgyGR5w PTZsBO6Bzp/epTJnF/VR8C3gNkY+hxgbgXDb X-Google-Smtp-Source: ABdhPJwEuBXuz53kqWJHuQd3HmWtXely2TzTrKv4yIHdO3BWD6+cVLl+4HEDbGKJXKGwITyH30fw5g== X-Received: by 2002:a17:906:1656:b0:6cf:571c:f91d with SMTP id n22-20020a170906165600b006cf571cf91dmr14296621ejd.377.1646759952463; Tue, 08 Mar 2022 09:19:12 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 06/26] usb: gadget: goku_udc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:58 +0100 Message-Id: <20220308171818.384491-7-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/goku_udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/goku_udc.c b/drivers/usb/gadget/udc/goku_udc.c index 3757a772a55e..bdc56b24b5c9 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, *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { spin_unlock_irqrestore (&dev->lock, flags); return -EINVAL; } From patchwork Tue Mar 8 17:17:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549651 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 1BF00C4332F for ; Tue, 8 Mar 2022 17:19:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349018AbiCHRUt (ORCPT ); Tue, 8 Mar 2022 12:20:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348915AbiCHRU2 (ORCPT ); Tue, 8 Mar 2022 12:20:28 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A546C1EAF3; Tue, 8 Mar 2022 09:19:16 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id kt27so40907349ejb.0; Tue, 08 Mar 2022 09:19:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xSwIYlrd4/uGvEtywTYOBSlI+/oM9Fdz2FSLOBGr2xA=; b=f82f42+N57pRAxK1PdtQfQj4EV2Dzh/MPG09nXy5zlY3XeI8nGy3r/XtVaZj5y814j I5RvcOiX9K4B0XHWrUqgSN5f+YN0AjRt9mlGOh2nm+Bvn1huEJmDo73cUitnPi6JgaAW sC2OR6jfGz7nids6AhjVhKJujGkL9BC+lDe9XfI9vwt4hN7YMuweP3wzPm8+wKsyeVyy 1OMAclsJJ1Tyoai3wW4RO0MI/Pn2aEIcrAkszGcuGuAGDmDu93YRnaTYuS2FLhxklcD5 SW4vUri6GNI2s48km3COIeUf7ysS4UuEdMsGgXnrJZgZagTqAbh0+AwXgRkp9H1+U/5n 7mpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xSwIYlrd4/uGvEtywTYOBSlI+/oM9Fdz2FSLOBGr2xA=; b=NQDFNgLSCcMFxaty/LqayHgo42WWTPcHV1gsXSrGgVzlCflrgkjrKgaE2cIBEt2c5u Nzuou0QjtNVXry+FOrUvcm8U4fnxZV5UZZ+uX0ZiZakAMNwmiD8cRjkAbW+21DsXRa+Z UtnXCvn8QV+XhpG16Mz2CxM/qzemzKUpcEr21QoX+EGW62p20vATTlGNbkcbXpN7DyFl zsrOH3AfA5oVgpr+y/x/xZB1w/4g0zFd6aFNfrtUdWzr6g2pcrfP3hNW0e2Hbe7xywUd JssFP9hmVKLh8YJWAL/O44WkHPuoX/YRhRK3KGEuRHcYfjE/q2QiPXQHcda7qaQ/Mu84 a85w== X-Gm-Message-State: AOAM533Qhs954xJxQwgy/w3dRVPI8KtA9kpOfz3PjKcOFo1uEKPQ6tYk zUP80hZ5yWea0Nw2jR8hsR4= X-Google-Smtp-Source: ABdhPJz9UfcDXea/5nQy+QRuBiqox5fM+PeNxCdRGj/ib2TEEALtD9dGo+U/+vlvR7k4ZgR0twFgnA== X-Received: by 2002:a17:906:c10b:b0:6da:a190:edb0 with SMTP id do11-20020a170906c10b00b006daa190edb0mr13847639ejc.512.1646759953551; Tue, 08 Mar 2022 09:19:13 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:13 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 07/26] usb: gadget: udc: gr_udc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:17:59 +0100 Message-Id: <20220308171818.384491-8-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c index 4b35739d3695..22096f8505de 100644 --- a/drivers/usb/gadget/udc/gr_udc.c +++ b/drivers/usb/gadget/udc/gr_udc.c @@ -1690,7 +1690,7 @@ static int gr_queue_ext(struct usb_ep *_ep, struct usb_request *_req, /* Dequeue JUST ONE request */ static int gr_dequeue(struct usb_ep *_ep, struct usb_request *_req) { - struct gr_request *req; + struct gr_request *req = NULL, *iter; struct gr_ep *ep; struct gr_udc *dev; int ret = 0; @@ -1710,11 +1710,13 @@ static int gr_dequeue(struct usb_ep *_ep, struct usb_request *_req) spin_lock_irqsave(&dev->lock, flags); /* Make sure it's actually queued on this endpoint */ - list_for_each_entry(req, &ep->queue, queue) { - if (&req->req == _req) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { ret = -EINVAL; goto out; } From patchwork Tue Mar 8 17:18:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550060 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 89AABC433EF for ; Tue, 8 Mar 2022 17:19:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349014AbiCHRUr (ORCPT ); Tue, 8 Mar 2022 12:20:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348921AbiCHRU2 (ORCPT ); Tue, 8 Mar 2022 12:20:28 -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 9463A53707; Tue, 8 Mar 2022 09:19:18 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id w4so22863337edc.7; Tue, 08 Mar 2022 09:19: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=f7/gAw+DbnZtTNdfpuzCiVdL6RMHX2i8psNGo9On2wE=; b=lZBLD5iJRHwna6Pu9qZ7/2APxDtkJaKEHwNbE6+HMjiGuMvomc/1zMzNkJChwYwOUC wh89YneS2YEvD1/3E6YiYRkJbMfG14PYEDSfnKDOcxnRP86SWcxS+yh4s7WyQE2Mitu1 5RtmU2GidWXd6f7WiJashE9Qqgssg/o/2ZRHgnj8zz4nFdcijcP2eAfyDFXkg/VziKBp fqFqBR0KEsNPf44Sn9hQfNdXuWNfTxuGjgHy8vmo3vjX+y4J4MTqLR7vzKlkakM9kzyh AUOXbd9aDkpQYqCJqZ+9+RAw+U9zUkeKnbcGsk+a55lXbgYXhRF0rEFrElYYIkfkmzSO Jb8w== 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=f7/gAw+DbnZtTNdfpuzCiVdL6RMHX2i8psNGo9On2wE=; b=g17PkaMpt9TAdx2L0O3mzOxEf1emtmZgiIHHQJpoVLDbo8n1q6qUBNY70sE7DeJ2NY xkV/R84n4Mj5Ce2d7xcXo/7XH9/sfV5oyP/ufIcyGuWoW6n3KHVGO1rCkyjPpF0V9cw5 373QoDst4MsN1oBC8UoM0W6BO7+qo6/BYpH3Cx/jSmeLaBvEUvh6+QWxhZYoMKwv6rbr aLe7hMcV2VZCAYfIR+aAfjZcv7Cx6zxHuEUWIsFq+8NiGffS2aZuSmfu9dj4+9+E0hnc 6rn9wIuqjLgLKe/vd2AZDJfWNp86gXWQcXrskBvynl4k1jk2dei9eSXgcwl56qMK2zik O9Lw== X-Gm-Message-State: AOAM531qaDBFcffJL6y41oZRcxWqIfeUB2x4lRV103jaUA1aMSkVuCXi zW1emPXMKCHBcpahNcWyLP8= X-Google-Smtp-Source: ABdhPJwKkX7DtmzDeIcS50PuB5Lq/wQhby7A+8VQURHoYiYvl5JNbYQ/SGWLW3UA2emPereAn1aNbw== X-Received: by 2002:a05:6402:268a:b0:416:7ed0:3f86 with SMTP id w10-20020a056402268a00b004167ed03f86mr589970edd.255.1646759954659; Tue, 08 Mar 2022 09:19:14 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 08/26] usb: gadget: lpc32xx_udc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:00 +0100 Message-Id: <20220308171818.384491-9-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/lpc32xx_udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/lpc32xx_udc.c b/drivers/usb/gadget/udc/lpc32xx_udc.c index a25d01c89564..6117ae8e7242 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, *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { spin_unlock_irqrestore(&ep->udc->lock, flags); return -EINVAL; } From patchwork Tue Mar 8 17:18:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550059 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 178FDC43217 for ; Tue, 8 Mar 2022 17:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348977AbiCHRUt (ORCPT ); Tue, 8 Mar 2022 12:20:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348967AbiCHRU3 (ORCPT ); Tue, 8 Mar 2022 12:20:29 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F193753722; Tue, 8 Mar 2022 09:19:18 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id y12so11870017edt.9; Tue, 08 Mar 2022 09:19: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=3Xwh55eQSwcaZtIpEuubEa3snJRYfJZKo0U9fl9zdsM=; b=kZW6WNMGUGI6UDsR0opMMiH9QjF42kdBFsKGj8pxgNk0fUXJE4VaWpA3y+2BA7jb1d f71X0i3Wb+QdCNyIhE+PeCVWIAWd63uiKMLJVpDHdJDnmUljnaL4cW/eCljJ3Ar46gHR JGumFuD6ofO0tQPnUTdNU12XPeeh2WedvZ8uaBNqPstdIdFYzk56dxRiEd6Wnw7z1KWG oq3rOADg6PFQpq0nYX4ksTx0zy6pmiuxAm6szUZ4zw2j19xIMGdzKvYuTkSJkEzxjusb zrJsvZ4llZkUKlbQLt0tmYB2dF1wvc2lNzB5V1LcBLo3w9l8sKSt9nrPyoURXmurKb5V 5KUw== 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=3Xwh55eQSwcaZtIpEuubEa3snJRYfJZKo0U9fl9zdsM=; b=eqxq2IrqCdI68OKkmtgahxEN8gW3khBjMnBsO+xZgeUKKfxGB+RDyn+d5nrlK9WmXu V2HcEJc1gRcYXmluAS9dsdHukFDjVqeNX7Euo1eeDvsGk73TRpNy3MwA68k0qid2NJcd AoRbMYv/ez/aHdyqiMXS10TdyDUh1ew1aJoGv/3GqnhrR0P+krhtLImJ2pkqGfi1nXxb 2iJLf0FzNNm287hr2jITT8TJLJKIY3bx847VLwvcnjqzEWtG9tHZzngvLTadQHYK6WDH XjhzfvCr6dCnVHbedQTxc/4vp60TwI/FeQG/FWG9+FE3+sGs8/oBD0B9M2+9wh18AJA4 cybA== X-Gm-Message-State: AOAM5323np29kEBEyLSJMoNikS/pPFRkwjG6IjI53P3h3EkLFQYVxqHD hH7PdxVNxotZa5WcNCJH4U8= X-Google-Smtp-Source: ABdhPJzn7nm9oRexQ46tTPbyy2OejdijLQSqD+yUfBb/3BUynmQMmnZSwgZZODE6fwhDJK11VmdRhQ== X-Received: by 2002:a05:6402:491:b0:413:6c2e:bb2c with SMTP id k17-20020a056402049100b004136c2ebb2cmr17355132edv.196.1646759955799; Tue, 08 Mar 2022 09:19:15 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 09/26] usb: gadget: mv_u3d: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:01 +0100 Message-Id: <20220308171818.384491-10-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/mv_u3d_core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/mv_u3d_core.c b/drivers/usb/gadget/udc/mv_u3d_core.c index a1057ddfbda3..598654a3cb41 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, *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { ret = -EINVAL; goto out; } From patchwork Tue Mar 8 17:18:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549650 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0E6DC433EF for ; Tue, 8 Mar 2022 17:19:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349024AbiCHRUu (ORCPT ); Tue, 8 Mar 2022 12:20:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348966AbiCHRU3 (ORCPT ); Tue, 8 Mar 2022 12:20:29 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A5CD5372D; Tue, 8 Mar 2022 09:19:19 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id x5so25369090edd.11; Tue, 08 Mar 2022 09:19:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N8sypLoqqUrLokDZ1BzWM/CJRguZ5x0Xpk1JVIhPD+M=; b=pzSWzeP0NZJI7823NFDxQfOeimyrLNPWnRxdQ0Q2zZpkwOJ2LxfVRP5kT/iVQkXkYP dJC4nMDHXqSVGosla1Mygiwl7sLIVTX+tGGNMRgeaGdvxUb4tOps1vVtEdMn+yGZ7YKQ jDCm8s401NwC61bRAOzIUso1sQKSPcOxyWze258ctr5oCmD0PKM4gxwvCVD+k2fs7fmQ m//ugy4ckRAT3cxsT4QFESj5lnwUzcFTm3YUaaFdd2sFxPjh+saGaDRbsfCnslazbefa 5PZa+CtTM7BwjhCTfWHlwIZKTaBay2BrcgsioorxDbFOPWApXR9ErdQukCMbUsrY7lA/ 3RKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N8sypLoqqUrLokDZ1BzWM/CJRguZ5x0Xpk1JVIhPD+M=; b=MiZeOifNf0lUCoJnAZXwJgNA5SexvFYargHLkd2mPwItTHc3PPfCVOqGZz4cRwK/M+ fGviOGxFGDf+VKPII6sniJxZe9LNtkkYMX2xSzT6qEcDg/2Q6SDqCUbCJuQNND32F38D ROvlBwj9aao0MnSz8HFWAs55XgE6BIU8oZwOgaqsiespKeKGQ5CsrT7KIIoVqOunuSko bGSkRkppZ9vWCDovOll9xVuMnA0mREJIO8t7aHAo5NhZBBGuTGEyKi5nw3jhfHYE1Mae bCLxWZ0Iq16WetND4i3Re6WHVas+/KQKGyQ7MKbV5VQldD8kbqEu3XuF+MhZOxDYgnNl VPgQ== X-Gm-Message-State: AOAM531AKtN9OV7iRJ2NwfdkKkZJDSzLSaEY8kAdBR0eADUuR+NPKxF4 qY3eAopSZzTtgNRVxNt43Hc= X-Google-Smtp-Source: ABdhPJya6Jg7Xf6nO/bt1TDUmz8xwHdfXlH0dr4/PEoFUpTykApNyQsj86pewvESMbIv/HizWDLnHg== X-Received: by 2002:a05:6402:d0d:b0:416:1d69:f23b with SMTP id eb13-20020a0564020d0d00b004161d69f23bmr17205986edb.141.1646759957318; Tue, 08 Mar 2022 09:19:17 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:16 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 10/26] usb: gadget: udc: mv_udc_core: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:02 +0100 Message-Id: <20220308171818.384491-11-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/mv_udc_core.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/mv_udc_core.c b/drivers/usb/gadget/udc/mv_udc_core.c index b6d34dda028b..fdb17d86cd65 100644 --- a/drivers/usb/gadget/udc/mv_udc_core.c +++ b/drivers/usb/gadget/udc/mv_udc_core.c @@ -771,7 +771,7 @@ static void mv_prime_ep(struct mv_ep *ep, struct mv_req *req) static int mv_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { struct mv_ep *ep = container_of(_ep, struct mv_ep, ep); - struct mv_req *req; + struct mv_req *req = NULL, *iter; struct mv_udc *udc = ep->udc; unsigned long flags; int stopped, ret = 0; @@ -793,11 +793,13 @@ static int mv_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) writel(epctrlx, &udc->op_regs->epctrlx[ep->ep_num]); /* make sure it's actually queued on this endpoint */ - list_for_each_entry(req, &ep->queue, queue) { - if (&req->req == _req) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { ret = -EINVAL; goto out; } From patchwork Tue Mar 8 17:18:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550058 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 B9B82C433EF for ; Tue, 8 Mar 2022 17:20:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349026AbiCHRUw (ORCPT ); Tue, 8 Mar 2022 12:20:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348971AbiCHRU3 (ORCPT ); Tue, 8 Mar 2022 12:20:29 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3063853737; Tue, 8 Mar 2022 09:19:20 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id d10so40740882eje.10; Tue, 08 Mar 2022 09:19: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=UBzUtejltuzioaBCpVkGKHSZS4YToJ0S8QSwWuTUsrA=; b=DS7uJaFqIcQLB59SzyS0eyDR+ZdfUSHmj1oWTQZ1VhQnZjri4p4CU444NxHEUdqBNl fzkjX60ppLKPVbMr6RtDLmz/ATtTQ8jicqYEsWJ7yhzJkSkWTT/V+Er+IHbeW/vDaSGF 2UNLPa+ksVub7Ze9jwpe9cdlPv4FRW0K2mgGlZI079XObPOY+Li12mR7SsSV4jaJl4P4 Lq5aIWxu1d4iJcXuquxYohpRfHgyOwXlOC4sXTKMdhXD6aktEtX+0fOeFlJeXZz0JfpG z1OFUT36WxiGon7Ud+UXMKzprB/IYNg18w37lW409ovU1axqlFAYPsuLBcv0/BcWOuK0 +zFw== 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=UBzUtejltuzioaBCpVkGKHSZS4YToJ0S8QSwWuTUsrA=; b=jK0JuAz0cF7Ks05gLWRl50mip3rdo7QX4hi5AvcJF0fIIVX2tWSPT9LHYpvTdmyS0j KMGufYxyiwm+NZMIlvmbb6696uOJ1QGmcBSMw8KB6NmxXouW13WCEZL3aSlnRFhTGj77 jYAa6vYcui4Er6EPz0lh0v6RFyxji+NIPoN0T60HQil+FySvtYdz37Ywq1OvE//geDQM S9xU5l5RkQLOQKB5OCTyQ/5ohTg4YnKqOaPaMZiop2Kw6NxoogHBoVGT9WROYp6VOV3/ 5DHhhMlzVlA1nDNC78rAe8znyew28BPh8NSsMi/X8zD4SEjFSkdDr7jjC7Le6CZcXmiz QrXA== X-Gm-Message-State: AOAM5329OkB68s4NF3K7JHz4I1nokEa+nEU5TpPjRBfN/RmPo9oudP8J 5CMQ+UQMuGcWXywOHpbz94k= X-Google-Smtp-Source: ABdhPJxP6O4XCst4o8tZ/QgBmL/GTjneslG5zm6PvJtE7Y0RINKU24/J4DqJLulT0771j9xeXRDqCw== X-Received: by 2002:a17:907:6e07:b0:6da:9722:8796 with SMTP id sd7-20020a1709076e0700b006da97228796mr13637953ejc.610.1646759958727; Tue, 08 Mar 2022 09:19:18 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:18 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 11/26] usb: gadget: net2272: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:03 +0100 Message-Id: <20220308171818.384491-12-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/net2272.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/udc/net2272.c b/drivers/usb/gadget/udc/net2272.c index 7c38057dcb4a..6a8884632273 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, *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + 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 Tue Mar 8 17:18:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550057 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 C75C3C433F5 for ; Tue, 8 Mar 2022 17:20:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242069AbiCHRU7 (ORCPT ); Tue, 8 Mar 2022 12:20:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244472AbiCHRUb (ORCPT ); Tue, 8 Mar 2022 12:20:31 -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 AAD2053B4F; Tue, 8 Mar 2022 09:19:21 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id q17so25425577edd.4; Tue, 08 Mar 2022 09:19:21 -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=1x89pBzvXuUZrfPfd2vnoyMWt4N2rOHe1CTdgdRQIBk=; b=CqwLW0HzXtny0uR8QmiWKYWH71xfwPXsvjGDJmOI+H1S7fXG94E92RbG0/RSjBLbZz wOzQzVMuExNIn+ntof9qnJuIqQVc0ryKecRsCwRdoxQ490atw7nk+JduUsu9oL/QNoXU ao17nfTKYxINgLtLy3sBmWClKm16Rw8oFNX35B275n6sPCHCOfkxnxaGgvLhTN9mJqhv TptbxEX1Aci/BDeFs0wKxuMZ//RPiWMLG9v1L1SLK8TtfW06A9SAjj1Kds2WqxtjOuzh lDO4OKALloSiywOC4aGb8wKE8OZhweohCvfYMkENj7MsEBPmUMQ7Zl1XZ3z4VqxPuNjZ YO8w== 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=1x89pBzvXuUZrfPfd2vnoyMWt4N2rOHe1CTdgdRQIBk=; b=a1vBU5jlLd4x7Ojhs6gEtZ8EbZnOHNPI+CiHCIEwU7kenRT2DJW8czHsSMc06YgMXS mL0M7HSFXPanZV4dVDcIprF82f205UiCOY4p0VDKzAuRH2B1ezIfQHRWFqXCXdSjDArQ 6lnTgH85TrYIWmZXgam+xtEE9NSBzRFWhWEc/ooFAsnU+32IxWpMPDQLdrkdKLpMXsdf 1QbOQK0TBe1tILaqzvXzjeHREgl0jOhenN6cz5bnpBx4ftJ59AqxgnZV7w18/xtak/b0 H2mD1z1mc6oIg4BwmVcCMeUk2WCA0NA8RSUfr2vcbLTUkZt/nf24fb2bEotVADnHe0vG UyQQ== X-Gm-Message-State: AOAM530fYTOKnQct9qtBMKD033EO+bpBpLjujuLP4wtkRFr5oyqYocUq IiXursBj7xeTV0C1Te6KoZI= X-Google-Smtp-Source: ABdhPJyYzbEjTcRWHRiyOXyo23qWETd0x7XVuzNY6tVPkyg+apzypsfIydk+P8ggPUYFphVZTJ0sWA== X-Received: by 2002:aa7:c946:0:b0:416:226f:f8a6 with SMTP id h6-20020aa7c946000000b00416226ff8a6mr8118515edt.360.1646759960161; Tue, 08 Mar 2022 09:19:20 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 12/26] usb: gadget: udc: net2280: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:04 +0100 Message-Id: <20220308171818.384491-13-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/net2280.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c index 16e7d2db6411..051d024b369e 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 *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + 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 Tue Mar 8 17:18:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549649 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 7F8BEC433EF for ; Tue, 8 Mar 2022 17:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348952AbiCHRU4 (ORCPT ); Tue, 8 Mar 2022 12:20:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348808AbiCHRUd (ORCPT ); Tue, 8 Mar 2022 12:20:33 -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 59FC453E38; Tue, 8 Mar 2022 09:19:23 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id h13so13273601ede.5; Tue, 08 Mar 2022 09:19: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=5DfRiN4tVEInDy1EaFlW5SfOWSz7K0FfgTOmN6xKLdM=; b=hb8FdLB1uM1UKpdPJwEPXncuuxGUo2wvVu7FMZEvId0f8lNvB/SYyf1WG2N9sZqfgp ONf7EkT/5NFZRrkb5nZcHlTkEo823pCm229yUB6t5pBkzC1esqh+mgWnQK8xOSFYYZT+ +9GwTybV0FJolqLU3f8kcJNlLvprhGzYJvvpzJsY7W+87+U/bZmQW1T5FDOQ8v+1jXkB gAlEw/HpCrkJSnRrdngIzrJhdeTzyVHDfDbKTNcUuTsWXSiCmxH+HCpBYEep5Rhu0nV2 GqWyn+Bau4wVoJdugkzsVR1UK3q4PwowaO3X7DIm+6IFxAdgcE1R9uXrwu0GXTL7JfIp Q5hw== 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=5DfRiN4tVEInDy1EaFlW5SfOWSz7K0FfgTOmN6xKLdM=; b=VrqAIXxQpT8vBi6DBLCg9738M0rMxT2lHPOBlufdtmz2RQL+Sza/yWjwVn1sPOPTUH Y2sDNfJneOLcuYuJfL03nSFJATpk4SrZ/6C3VFUQ2XR43WNRpCJr73zviPi581PXUZCP k0v4pdAJBgcDoQCs7zfWZH+JeZ0z/N9eGW2m9gLrWZeBNOLe5OWZ5U17qc5GExZtKJDC yWHShY6wPLLoNU58T5HDU5Yd3Q65vL9fZSKIDVMhYrjaTEwCna7pNmmVkFXEjYMyYMXA Ee1Hvge4Zkqq+iHhISNC8DqSBFjcu6usW6sJ+bEzq0FJD1Q94TPLR3HGhSK3aaHkJx1b M7hA== X-Gm-Message-State: AOAM532HEzucO7Z+xPGLlgLFD7c9wksMpYTvvST0RjIgxJx6sXN4MX8K PXc2IYn308pyNEIIzCsha/c= X-Google-Smtp-Source: ABdhPJx5czam/LGVZPYwb0egaL0FVjfrwCPS7zG4IWJTAsKhpAMjuNXf6RzEKFj7FDaxzZ1pYO9iWw== X-Received: by 2002:aa7:c3d8:0:b0:415:a0a9:1f18 with SMTP id l24-20020aa7c3d8000000b00415a0a91f18mr16877614edr.412.1646759961620; Tue, 08 Mar 2022 09:19:21 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 13/26] usb: gadget: omap_udc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:05 +0100 Message-Id: <20220308171818.384491-14-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/omap_udc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/omap_udc.c b/drivers/usb/gadget/udc/omap_udc.c index 494da00398d7..2d9815dad2ff 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, *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + break; } - if (&req->req != _req) { + if (!req) { spin_unlock_irqrestore(&ep->udc->lock, flags); return -EINVAL; } From patchwork Tue Mar 8 17:18:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 550055 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 8CB85C433FE for ; Tue, 8 Mar 2022 17:20:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348995AbiCHRVG (ORCPT ); Tue, 8 Mar 2022 12:21:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348886AbiCHRUe (ORCPT ); Tue, 8 Mar 2022 12:20:34 -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 88AAE53734; Tue, 8 Mar 2022 09:19:24 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id qa43so40692680ejc.12; Tue, 08 Mar 2022 09:19: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=/HJBUWhz/z+yBIrs52yUQQJ33J6nMXIA1Dz3yTWuABU=; b=IZQCllcOhtivjRo00b2pdzZT1W1c9bLZrrhcqB6v9pBeI0JoJnJI6tN/Fm3HrUJMXK toBezpDJIY7dT0ixx4jlVSct6prrJrxoRlYjYPcveF4Qzi4Sm6jk+uJiIDKempwEi6v8 6IweS5QMDulsYYOcygMq9u5QWMWzy/Zd1XvYlGnftuCWOKnJItF182wm35/lZB9f3RTA 6CImUU7Wejii4psfBf623MONv+qSBsbM/TqfCP6HI0zWwgzOp0ZFNO/rAn60kx6ZF8YI qOR53Lf98kAw1z3U0by6WNUXloxZwTpUSSMDIYlP35zSlSdlOfwt/xUv/em+4MYEIRYq WlzA== 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=/HJBUWhz/z+yBIrs52yUQQJ33J6nMXIA1Dz3yTWuABU=; b=qTjeXelkKHcOHW8y0CGHRLY0pwZ/+kf8FWbfaVOD7JysIXTbJu6l/r7R+kkLOLQflq wA6GbYF4ZWTgr6s7Fp/Pn7N3mLOdvcSfJWNAnCjm9AaKtvF/WCS7+hggJ+imM3zxJU7G Oa7VozVFlY14tziSHxTeSq9up1kDFpr/kzREQzwZcXGwYVql3NufiK2Sby6rvGSQhToi YHZecmj5xIfyW9ZyV8J6ZlqWUgFGVQ72QKPMEtNXycjiBMGzle/yYSAxv4q3Ff2OeB7d Hfpp0WX0JTPJ8h91tOMLN1w6eehgPWL9KgpML5xuSFn/u1Y0+pux9dLBJQGtOxPXcvwk 7vpQ== X-Gm-Message-State: AOAM532Ml+y0l0r2z1lsk3thgyYD9ALMf2OZZG/BPRXezlv/XXYOR00d oY0HfkWSQqocm7BHVF2hvO6I7AyETCNUew== X-Google-Smtp-Source: ABdhPJwxySYfIab31wVLTlBFHM59OFhBbDQYZ1H5XMGhoT32J5qfAoS4xgO3IxB6fBIWkcjHofpmUQ== X-Received: by 2002:a17:906:c20f:b0:6db:b5e:b129 with SMTP id d15-20020a170906c20f00b006db0b5eb129mr11985182ejz.552.1646759963047; Tue, 08 Mar 2022 09:19:23 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 14/26] usb: gadget: s3c-hsudc: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:06 +0100 Message-Id: <20220308171818.384491-15-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/s3c-hsudc.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/s3c-hsudc.c b/drivers/usb/gadget/udc/s3c-hsudc.c index 89f1f8c9f02e..bf803e013458 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, *iter; 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) - break; + list_for_each_entry(iter, &hsep->queue, queue) { + if (&iter->req != _req) + continue; + hsreq = iter; + break; } - if (&hsreq->req != _req) { + if (!hsreq) { spin_unlock_irqrestore(&hsudc->lock, flags); return -EINVAL; } From patchwork Tue Mar 8 17:18:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549648 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 4D0B2C4332F for ; Tue, 8 Mar 2022 17:20:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348884AbiCHRVD (ORCPT ); Tue, 8 Mar 2022 12:21:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347264AbiCHRUe (ORCPT ); Tue, 8 Mar 2022 12:20:34 -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 038E554181; Tue, 8 Mar 2022 09:19:26 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id gb39so40699793ejc.1; Tue, 08 Mar 2022 09:19: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=hQwhyeIJaS4gMMq4l8hfR9wNOecju8wIT5izOR26pg0=; b=BWdxPDq2ZGBk8E3khwO51OqDkZJNaD6HU3ZxJ5Qp4fAvWOdBGGpbwdk2CV+xsBdNnF Ugwrz4wTDHSN0yyyTHPDU8/vaZiAqIR+Ul89aVxUH0Zjq8OVsVOApy+ozsZ6qANKW/dl Gzw1Bv2FzODw0eQNRuST41XG2QbkzHga0EFWjhOhiIjVbHEM+Xr9WbH/anVxY4qvb/w5 UsNjZ5qTyyhg/TxxezbZhKzv+QarI/2PJz6mAH9fGi4ZCQ0SBsPNmGICRDSkNpZDcIBz j+UNQB91oDJurEXFz+Ex6uTynCvWPTUlfWjqTDg9PzVHD00fcIuqmzasc2hlMUIBGXIp 48Ig== 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=hQwhyeIJaS4gMMq4l8hfR9wNOecju8wIT5izOR26pg0=; b=LvMUpZuU7sVBAE3n6AcoErPMDDajeZDAfJZauasOmWbnGhcOh/mY66xOlgP9FZ8Mlg t1nbVBGg9X8BT3mKFpEPXlEqfQoyNNTbwVg5aD1bcMChQKOyuP83XiKCNk2tpl+247Sl Hpv/h5vCy1ze4uuJvTPiS8AD+z66RC9cdV8xlZbzaaafnD8LJP5vcIWeABAlFG2vuTI+ KFCObThaa6FClVMWQXVTvpEZf2R+CaI0deFM+YqLQLmgyfLDtf769jd/+rLvtfSBp0i4 t6wpdOmHZJ9TbNDJD5kmucD4yENe34EHm65CDPByO83Ws3YZcqn1AU9QBGrHwFP7HFW8 HADw== X-Gm-Message-State: AOAM532mBX9Xy6z1rTFiX1lVz0OinerrztDVajaqdYlDz+J0XyFPL1zW S+OYhRvH229h+lG0Plk4rRM= X-Google-Smtp-Source: ABdhPJwRoyguc37yxeKFidsAA1N5VJnbQ14wYHVgwTkFcutCYNMVZVL1aLsRJOpQLSCZ0bA2rg2U/g== X-Received: by 2002:a17:907:3e94:b0:6d1:d64e:3141 with SMTP id hs20-20020a1709073e9400b006d1d64e3141mr13580383ejc.213.1646759964460; Tue, 08 Mar 2022 09:19:24 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 15/26] usb: gadget: udc-xilinx: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:07 +0100 Message-Id: <20220308171818.384491-16-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/udc-xilinx.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/udc-xilinx.c b/drivers/usb/gadget/udc/udc-xilinx.c index 2907fad04e2c..428c755cf2e1 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 *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->usb_req != _req) + continue; + req = iter; + break; } - if (&req->usb_req != _req) { + if (!req) { spin_unlock_irqrestore(&udc->lock, flags); return -EINVAL; } From patchwork Tue Mar 8 17:18:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 549647 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 11AFFC433F5 for ; Tue, 8 Mar 2022 17:20:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348911AbiCHRVF (ORCPT ); Tue, 8 Mar 2022 12:21:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348918AbiCHRUe (ORCPT ); Tue, 8 Mar 2022 12:20:34 -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 55C7754182; Tue, 8 Mar 2022 09:19:27 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id qt6so40750895ejb.11; Tue, 08 Mar 2022 09:19: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=xUQEfJ5ZyqNSxudWIneiwonLdZGLhD66gLNXujXNkd0=; b=e87KtjYpoNsPCzLOIfYAyMDd/So++VJyylS8RdS1RRJzLuwu7o4BtMGOZbLoBldbHz N7FnyIBi6zl5w/GWkNSankQUwGqwHJNPgOpk30+IW3nNST+8DZvRqkN1MF6ZpZgmB9Vo UEb/n6ESITLzMxCtjhkTX70+6TYpzvtwhJREeW63BpRRqAnMBx+dW0bIEUaiYLrI4H6/ 9eR8p92+Fou6PoMTYOPzM+XH55UkHXR5l0sB2QRQh/SIv3mGDnyDl+6DnAAn0hOMFvpb 2dpdK+JSq1RIO4nmPd/6CTbSp/+NMnocsbpRCZgNzUg3r92b3L76ZOv7dsRboP4Bhc7v D0nQ== 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=xUQEfJ5ZyqNSxudWIneiwonLdZGLhD66gLNXujXNkd0=; b=v3dlXAhI/kqlSRxaM087RUb58roY4vzunGQ8RcdKMqtek2TwZ2dY4Fj5sIXqVxZgHJ kyosCw5vlHMRn/vkedlwyzNl3WWY/Ppq2geyuD4kwhQZ9qvft2xiX958sZSzE/GRB3sB rlvh5UPPbuCHBbzB9e1DqndWEVtU9iOQLUZq7CPRilm7e19bMQo2rXYm26Lgn3SdK09C aJzawBoAh47nKaL00TZyivkNL9lWCTBu9oBKIW0cLja/kzJu4dr1EoVy59VQ+jGQo4H8 FcVghuGBFrrPSCehx8A3lhWZrbsZ5jEwLWn7rVz9LECUanTC62vS9Q0hT62UhROir0/N tHRw== X-Gm-Message-State: AOAM531yAIogFZ+INAnvBFzOR4BpjZY8ndWTJN+68cD/nIToxz1kC84M 1YU6PqJr8BIq8DtxkXPqdkQ= X-Google-Smtp-Source: ABdhPJz+PlyR0JPgtg3UxzSVkWCXAEbjloQHheDZopV7MNYQRXqYrxL4cAYKpfPsc8xd0W6WR6aB6Q== X-Received: by 2002:a17:906:dc10:b0:6da:f383:86ed with SMTP id yy16-20020a170906dc1000b006daf38386edmr14048197ejb.391.1646759965847; Tue, 08 Mar 2022 09:19:25 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 16/26] usb: gadget: aspeed: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:08 +0100 Message-Id: <20220308171818.384491-17-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list representing the request queue does not contain the expected request, the value of the list_for_each_entry() iterator will not point to a valid structure. To avoid type confusion in such case, the list iterator scope will be limited to the list_for_each_entry() loop. In preparation to limiting scope of the list iterator to the list traversal loop, use a dedicated pointer to point to the found request object [1]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/aspeed-vhub/epn.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/aspeed-vhub/epn.c b/drivers/usb/gadget/udc/aspeed-vhub/epn.c index 917892ca8753..b5252880b389 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, *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != u_req) + continue; + req = iter; + break; } - if (&req->req == u_req) { + if (req) { EPVDBG(ep, "dequeue req @%p active=%d\n", req, req->active); if (req->active) From patchwork Tue Mar 8 17:18: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: 550056 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 F0D08C433EF for ; Tue, 8 Mar 2022 17:20:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348990AbiCHRVE (ORCPT ); Tue, 8 Mar 2022 12:21:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348950AbiCHRUf (ORCPT ); Tue, 8 Mar 2022 12:20:35 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C108554188; Tue, 8 Mar 2022 09:19:28 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id d10so40741770eje.10; Tue, 08 Mar 2022 09:19: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=/dCBmFHyxMjKmIC0BzCXvYVTfa0KQ4RHK39a2T0M4mE=; b=Bb/qUdXLbI2rwxQQMu/NXlm53haClXaykwRIg8u9pDWFTx/EcM0B/6sLJeI2nRNw5m fkuS1QUg3euOCPRq6PgACL9W9TEMqDbVO+F/9HNXGb17eKcDOhbQ40Lvb5vUDYlGYxND CMDN/8o6vG0zGVgVV8jJdsCjZn4yhrAHze5oqXR9DZjrPZM17pMTmlVTHUgppCwlcCtz 74FFMi68L8NEgU0Eqks7Z88FYfr4TWzIpJmPlTIZ0hmHllhV8IXEGv7pxjo9cGKSVWrN LF4fFpbg3EDbb9DdijKNsh64aBRfjMWkPK1D8C5EF42ocBvIFabVs7XrKp2N6LojEQ1L vByQ== 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=/dCBmFHyxMjKmIC0BzCXvYVTfa0KQ4RHK39a2T0M4mE=; b=NlI3cW13+gB0OaTVRdtD+qxo2TwYS+GKPxJLZaHEMsmfre1DkkesrwDGfLqqdxQUP8 nxT/RE9lo08SOXQyRUpKN+r6BWnGyNB1rKjXmBaCbEINzu/9a8ufKiPpkjYyU2MI4Til icnsXNHrAzk73Batv3jpQZrXA7lhVgML8FbUtHLig5117otJnVxQB2hY/QqXx84ZMYSC Yth2BDXfTlSrDtLVBNdjr6VAf7yBPhG0muJNZZ55O31FQSPlBaoatXgFTdaB0rbIfHgJ zwxvdh2Qi3GaBjR85NY6fGYnjA08ZMuHvfDY2zyuEQ1UyPzBjS7jHi2eRYAhsbtDGhQT Nacw== X-Gm-Message-State: AOAM532rg18ho2iR8OU4ti1TtKfpGlkg6C5ijgvw/C1+nyxR1cawBHua UzneGtXiHTY5SJ3tYhKJkDs= X-Google-Smtp-Source: ABdhPJyuvZYmtYBOzs6KBwHbp9aTbm0jKyEeELbbNjtuD1H+7NenLtfzjI2i6hyHwvrqjcNNgcDS/A== X-Received: by 2002:a17:906:b893:b0:6da:ab5e:ea34 with SMTP id hb19-20020a170906b89300b006daab5eea34mr14196897ejb.657.1646759967292; Tue, 08 Mar 2022 09:19:27 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 17/26] usb: gadget: configfs: remove using list iterator after loop body as a ptr Date: Tue, 8 Mar 2022 18:18:09 +0100 Message-Id: <20220308171818.384491-18-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list 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 | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index d4a678c0806e..1fb837d9271e 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, *iter; 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) - break; + list_for_each_entry(iter, &gi->available_func, cfs_list) { + if (iter != fi) + continue; + a_fi = iter; + 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, *iter; int ret; mutex_lock(&gi->lock); - list_for_each_entry(c, &cdev->configs, list) { - if (c == &c_target->c) - break; + list_for_each_entry(iter, &cdev->configs, list) { + if (iter != &c_target->c) + continue; + c = iter; + break; } - if (c != &c_target->c) { + if (!c) { ret = -EINVAL; goto out; } From patchwork Tue Mar 8 17:18: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: 549645 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 E1717C433FE for ; Tue, 8 Mar 2022 17:20:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244081AbiCHRVL (ORCPT ); Tue, 8 Mar 2022 12:21:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348986AbiCHRUh (ORCPT ); Tue, 8 Mar 2022 12:20:37 -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 766E253B68; Tue, 8 Mar 2022 09:19:30 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id yy13so31927368ejb.2; Tue, 08 Mar 2022 09:19: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=fephKwqGahaE5ePrpyTUfZ7vzKqhC09iEtMfdAncdNM=; b=bRM/OMuDGEv0AZGOOzGCmNCsSpySNqu07Hft34oEc9A6ak9XMmK+29xqpHDV97GpvA 6zbYVmumIsOBgZnKtMh6+nvYaWqVcsUUWykf2ErUi5J6RWqEYk5ALbCHPcgq3K9dM25m cDhwwdMGrtjPdIWCfavmaPo2986IKJvS1y1Bg4OTJML9wNk7hnOF2hf+Zy55CQHZGnMi WOWCMvczodHmb4pi1JqtcqWldbpEJIUiFXKBZsOXYBbKVehmE+5GjDvhFXB2+3bL0z0C O4XG2LrZZ17yMk4WfeRr1QGFuct9eYkq0XdaIUzNsdLmjDhbyFOg7wkjUakFPNNOzmje 520w== 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=fephKwqGahaE5ePrpyTUfZ7vzKqhC09iEtMfdAncdNM=; b=5/Wkr7fESjE9VSpIM61L2GEyQn5z4hg5sjAn0mTut5hprYvs1GkDOfQCMEt9Pnz+cP B1o5qOLi1CL7GYcafAJWGUDYkww9irNIov9/+YKKhnyhJ5ISJl6l92ixMlqEP9ku//rf WIysA9+/Tc1QURkIyg80oVYiBHpf0QrVTGUAZskK8hgGf0M0DyTBJplKCKOtMaOKIeDU AEJNjbsAIedDNkOWF2sZ7JpahakpRGar7F796NVaUbQzZvMK25pHkMee+Q3LDiC0lNp5 HpJgh+MN+eaTkM7eYBV2uGpCAbiUzCbc8n41uEAsZZ0GTAxEHNSXWOIbDmfDQbTbuaxd Ds3w== X-Gm-Message-State: AOAM532okICEXspmjRJg7Md8uVa1lULR5i3iCnzR4G3Ws+VIxVzGKRHu vdrMGMrK4zOrF0cIDtzWmlY= X-Google-Smtp-Source: ABdhPJxByY5nw9jmtNB7IUcf/8bjjy7qzOQPkkkPtk4UKkjYZWHA8u51uU9OkIsMOffHmN06pgZUag== X-Received: by 2002:a17:907:961b:b0:6d9:acb0:5403 with SMTP id gb27-20020a170907961b00b006d9acb05403mr14001239ejc.568.1646759968956; Tue, 08 Mar 2022 09:19:28 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 18/26] usb: gadget: legacy: remove using list iterator after loop body as a ptr Date: Tue, 8 Mar 2022 18:18:10 +0100 Message-Id: <20220308171818.384491-19-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list 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..1187ee4f316a 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, *iter_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(iter_n, &hidg_func_list, node) { + iter_n->fi = usb_get_function_instance("hid"); + if (IS_ERR(iter_n->fi)) { + status = PTR_ERR(iter_n->fi); + n = iter_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(iter_n->fi, struct f_hid_opts, func_inst); + hid_opts->subclass = iter_n->func->subclass; + hid_opts->protocol = iter_n->func->protocol; + hid_opts->report_length = iter_n->func->report_length; + hid_opts->report_desc_length = iter_n->func->report_desc_length; + hid_opts->report_desc = iter_n->func->report_desc; } From patchwork Tue Mar 8 17:18: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: 550054 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 E66A4C433EF for ; Tue, 8 Mar 2022 17:20:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347606AbiCHRVK (ORCPT ); Tue, 8 Mar 2022 12:21:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348994AbiCHRUk (ORCPT ); Tue, 8 Mar 2022 12:20:40 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE3E9541AC; Tue, 8 Mar 2022 09:19:31 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id bg10so40814643ejb.4; Tue, 08 Mar 2022 09:19:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CGvztHQgMCmpi1WqEUxl2BM0vU36m9yBUx2ET9/vf+0=; b=YyrXukfMZwnEEZrPAwnqcHzxASANGmibqZoi/p2nngxd92F83KKYuhPvflo1n7UjZ/ ce79fBag3W+VLCbRaMz2UfupvxNw6V5dwuRHtgFIAyGBakgm3YNqPDvDnAoL8Mhccamq dsEQWyykl7Ze0+Tgy3DxSjxvraHDf9PzeGMiU+y2yihQWx3vkNtOEjUhI0gqFxnHqcqx 05Y1huktCi5BqrKAiaBtMnVyRKwDkJNtWgFNxGLGFsdLPr8Uy0uFU6cwI9Xd3uI5sRGn CEkqG8+A799Re+i75Xi8rUdTGS2TMSRlANNSmycqyufFEw12xKqCjePBc1akYMKxt55q qESA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CGvztHQgMCmpi1WqEUxl2BM0vU36m9yBUx2ET9/vf+0=; b=gfmrwf0QhuAwSYHtfrmbCOtOAYMnzZhh89tFTmCy8jk3Os0+qeSXi/HsOUeAL0uHX/ 8t5Unynqf98WmzAL02dsaKiETn5e8Zh4Mu2iDvuMdA/dWE1jzJ1KeORK2qDQRNyHTdNy BQ00yUKJwHKcAg2Cx+ys0bxASuAgpGBkcSaQh+ej0aomieC+OCxKfuf0jw7c68bI6ZLx 5EPUvMJkeV+yq1noKAGLv75AnRmQVfYdH6XaxNn+9gjnIlqEA6SpZlMk+uQDDYh840ot kQiuSX4bcMAgAdWp1veOv36C61rs8fu6uPfyqxVSoDzoWvtzN9JusPR2NgTHJqxLQeca YwhA== X-Gm-Message-State: AOAM5306RTTssOTmlUOUbGl7cIVpZk+y+FbmaBj7XFYlFw5NGTDRtGVO 9a8h4Xcip6hLg4gCbE+wMJ8= X-Google-Smtp-Source: ABdhPJxqTg0GziD1cdaKhTgOaoQ1oh4ah0h7WtaZ2oq/YqBiCtz55nU1fdk6ICxaN/CpfIvCnfEA9Q== X-Received: by 2002:a17:906:6a81:b0:6da:d7e5:4fa with SMTP id p1-20020a1709066a8100b006dad7e504famr13910360ejr.223.1646759970436; Tue, 08 Mar 2022 09:19:30 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:30 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 19/26] usb: gadget: udc: max3420_udc: remove using list iterator after loop body as a ptr Date: Tue, 8 Mar 2022 18:18:11 +0100 Message-Id: <20220308171818.384491-20-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 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 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/usb/gadget/udc/max3420_udc.c b/drivers/usb/gadget/udc/max3420_udc.c index d2a2b20cc1ad..ac8a46bc1057 100644 --- a/drivers/usb/gadget/udc/max3420_udc.c +++ b/drivers/usb/gadget/udc/max3420_udc.c @@ -1044,22 +1044,26 @@ static int max3420_ep_queue(struct usb_ep *_ep, struct usb_request *_req, static int max3420_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req) { - struct max3420_req *t, *req = to_max3420_req(_req); + struct max3420_req *t = NULL; + struct max3420_req *req = to_max3420_req(_req); + struct max3420_req *iter; struct max3420_ep *ep = to_max3420_ep(_ep); unsigned long flags; spin_lock_irqsave(&ep->lock, flags); /* Pluck the descriptor from queue */ - list_for_each_entry(t, &ep->queue, queue) - if (t == req) { - list_del_init(&req->queue); - break; - } + list_for_each_entry(iter, &ep->queue, queue) { + if (iter != req) + continue; + list_del_init(&req->queue); + t = iter; + break; + } spin_unlock_irqrestore(&ep->lock, flags); - if (t == req) + if (t) max3420_req_done(req, -ECONNRESET); return 0; From patchwork Tue Mar 8 17:18: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: 549646 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 D45FDC433F5 for ; Tue, 8 Mar 2022 17:20:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348985AbiCHRVH (ORCPT ); Tue, 8 Mar 2022 12:21:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348993AbiCHRUk (ORCPT ); Tue, 8 Mar 2022 12:20:40 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EB9B53B76; Tue, 8 Mar 2022 09:19:33 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id bi12so27680032ejb.3; Tue, 08 Mar 2022 09:19: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=vIp5MlXygySPCwO7mdoHIhdgzDhIp7fZD6S7LhPAPYQ=; b=WlNGKUPak1CvnPMtyNgNi2hWe8vUySX3SFUz0MyTpUDSLIpJ3OXgXlHe5Z1opA92YF xXAAHkz8XTizVzSD0t1S26O3Sfk/aV7F2fGP/YMUxOdylQjf+MpRz9OgNgz9QOjAuHcA u4WsKLMoKmjOJ5ObJpVPRRAhDxICwxssyIvje4f5+I6GYkRoUAWDamD+ZAvAmXuAdNmg qAX3AHnvXyq5C8B9+4jLXMjdGcDSSHhXAJxekiGbM1vfdW2TnlBf3o5M91Bg1POzmYjh lFFDfc+bdmvWomVlY0cXSAPO8iyPyqQwhjvQBJw2OTQ3MfrxV2pWHcixqALu0MaHvnPY Gy/w== 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=vIp5MlXygySPCwO7mdoHIhdgzDhIp7fZD6S7LhPAPYQ=; b=mvxAaTNrh295U0aC6vTOEEhFQZowqNXfTeleX+mz0nDXncdyVuEHbBCDI1vne0yqKV oDHRl3v0w+x4iQrzhMyoJMwYNM6ONbaGDGuhkNN8BF5CWnwVK2lsgrjM7MhDvSwUIIhz WBp7mhXid9q8fjjIOcPd8ejANaBCZLSUnxaHchczXtafkqURZYRs/0f68Zp208jCbyNh 2Qt3ixnnQkUuvj0EROYq0twcPHORQOkONw6e2i08TxhHI1XCFCXMGM5apPNu/AvV3Mjg ZvDdLMmOZQgV2/WelT2CY90+FtY22eDDDgPGOmMA4d4qqnKAnqs7SoBDbw5QFDXjdDkI CYqg== X-Gm-Message-State: AOAM5336Xn/Vx2ki2xBW06kq9JWEJnTZAmBJUuZ26m+msCMXhA4CfN6L cIa5sEohvshvYqIl7Wr2NDc= X-Google-Smtp-Source: ABdhPJwtX9Kqt5JbkWYPOZX7P2BCkV6Jk3TMjuPgoWOEpjqEJdNmLZBNuWS/ViFn1NpkTkKxghLTHw== X-Received: by 2002:a17:907:2d11:b0:6da:924b:748f with SMTP id gs17-20020a1709072d1100b006da924b748fmr13877030ejc.584.1646759971897; Tue, 08 Mar 2022 09:19:31 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 20/26] usb: gadget: tegra-xudc: remove using list iterator after loop body as a ptr Date: Tue, 8 Mar 2022 18:18:12 +0100 Message-Id: <20220308171818.384491-21-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org If the list 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 | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/tegra-xudc.c b/drivers/usb/gadget/udc/tegra-xudc.c index 43f1b0d461c1..1ad616d81c96 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, *iter; 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) - break; + list_for_each_entry(iter, &ep->queue, list) { + if (iter != req) + continue; + r = iter; + break; } - if (r != req) + if (!r) return -EINVAL; /* Request hasn't been queued in the transfer ring yet. */ From patchwork Tue Mar 8 17:18: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: 550053 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 EE432C433EF for ; Tue, 8 Mar 2022 17:20:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349074AbiCHRVO (ORCPT ); Tue, 8 Mar 2022 12:21:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349003AbiCHRUn (ORCPT ); Tue, 8 Mar 2022 12:20:43 -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 BD1B553E0E; Tue, 8 Mar 2022 09:19:34 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id h13so13274283ede.5; Tue, 08 Mar 2022 09:19: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=2tLXmXSOjUs3IAXSFXQ9uS1yTf2MJG7I5qLldTbEnao=; b=ZwQv+ZYzEbmyyGZyL9N4a6ggod4N1RlbBwdslw7vDBQMj/75ezmdGmg4mRX8YSOx1T 6mih52OI+PHzzaVbIu92wqChc+JDtorksT7ddIhQiEM9qKAJVnH6y55VF4nkpswXg/pK jf5esaFh4w5zRIHaWk6VvqUZY9VTjosQyLrl4ra4afLigz0qJ4orV02FGpopf9cMeWKR 3Dqu6bLnzKf1AgE6XXARBy5mJfpxn9XiYNwjL22Mo5BduOvzkZUMxAE97QN3n/CMfuRs 6OTDK+Lk9OhThCuG/jFqxw/W2yzBT0EDiSMx/14uiCnPQsRUfHR8hbFtMQuhyP/SBsl8 9VcQ== 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=2tLXmXSOjUs3IAXSFXQ9uS1yTf2MJG7I5qLldTbEnao=; b=ZxF4MKYghMx6f19OXdYZvK8joIdbAXV6DH9mWBNULMky1ssq3qdA7J1opKHhN954Az 5/lV2n/YDcxwbs7dxrsN612PIv2AB9Frg7e0VwGj7QN8cDVzAsX3qTWz6QDsFTQYxXiZ bjJb1i3jufNYPpu5rj4zYHQQWLULSvWOt91DKjTkjf+q6BITNaIY9qx+TVBzrhybvrS/ XvLGS37n/bCuVI/JbjdLIYyF7aMrjUDLmBE8+9kFVx9o+9jb9ZpKVuLmbp3iUDptyuIA gA/jPQRC8pwgVikffB7TyFes1jsvJZxiyt7pZmMr9jJSO1N7ElJP/sG6Mpc6WVLt0D7P BRQQ== X-Gm-Message-State: AOAM532haSTvqfE/rOveIw4TDEPYmqr/1cuHjyzBj+zhCb3pAeMd3sTX ddLdCJevJYhGrOxvnucIcPQ= X-Google-Smtp-Source: ABdhPJxiCgTengE/g8GyC8s54Z2vH1A4Pir28u+kldhuED5xvUq3bdnmEm833lpJDcdHZTZxRKPJ4w== X-Received: by 2002:a05:6402:5cb:b0:415:e04a:5230 with SMTP id n11-20020a05640205cb00b00415e04a5230mr17277809edx.352.1646759973277; Tue, 08 Mar 2022 09:19:33 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 21/26] usb: gadget: composite: remove check of list iterator against head past the loop body Date: Tue, 8 Mar 2022 18:18:13 +0100 Message-Id: <20220308171818.384491-22-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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..4f7e789c3e07 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 *iter; 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(iter, &cdev->config->functions, list) { + if (test_bit(endp, iter->endpoints)) { + f = iter; break; + } } - if (&f->list == &cdev->config->functions) - f = NULL; break; } try_fun_setup: From patchwork Tue Mar 8 17:18: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: 549644 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 8BA49C433FE for ; Tue, 8 Mar 2022 17:20:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349011AbiCHRV2 (ORCPT ); Tue, 8 Mar 2022 12:21:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348959AbiCHRUq (ORCPT ); Tue, 8 Mar 2022 12:20:46 -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 3E91A53E1F; Tue, 8 Mar 2022 09:19:36 -0800 (PST) Received: by mail-ed1-x532.google.com with SMTP id m12so391022edc.12; Tue, 08 Mar 2022 09:19: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=g5Y06zvKlJUEjDmKObk/clZZO1QM0n1/SCAkFoYndKQ=; b=Gd9DBm1dezIaoJ0IY/Q/VLpNml3yDUDKwBaRU0IeGh8DxrfFqBsXZUOqx4x89KIeuw Dxhh7KDvlWrhT+IB52yEIwszEj1r2/qfylXJnW0tORNBvXogAl5HBTDJ3iBUbaYjaicg y2vHSn99UOSrOMrKShIUmVA8Q/hR2UvqOsYxv4d/4D4oO6ZfAeI1GsLXIXAGEZ81NOBC dJIL1kdIF+4TE/1niYe4ewQXYTCRhow7JzZGWBTWSqUVLTN8t8geZO59uF0eNU4HFN/m qCXDQbldJrEflaNbeWT3Qg0jU1vSWr576FCoAALf4dn3ta2hx3cp3HWoueLCCwufefzA DwrQ== 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=g5Y06zvKlJUEjDmKObk/clZZO1QM0n1/SCAkFoYndKQ=; b=OCGcMM0cAnGtnFq6G3Bv3Z39fINpduiSjYrQJIyoR+0d6jkxbiSlbSItiuwoYg+qQy EB5pDBdJnK0Llo1y//ulC6fARc7gbrUln5W2kc23RbzltzNQWcpCpKxf/RZYypnkwGOL z5nQWdBCMp/AwyIbQh5474il4jLLktyVURldXu6OntGEvR6Cm6GS+JkjyUR+CKtDMyUL nIrEvBbCTzE0mtBWVzuDO4qltMdkathzBMS2S3IRw+INPQG2NYQCrmYVQyqM1Gh48gU0 MvRkqwP+9gzxJm7a1op/ztp+3feSLPiF71Q1EgF3cJ7fkwKcfg3zdceIZzE2AIRAZypM rgBw== X-Gm-Message-State: AOAM530ITI/q2guhf7qNM6q6Dmba8/xJDXk+RTnGdar5CaPvwN0rn6/J /fOcYqM58Z9NSTsBn9/sLXY= X-Google-Smtp-Source: ABdhPJx6vcPNNpHlAtzoO0iFHCq6XDejuswT7N0EiUfkMYNL/8Iu1FFDhGZpjnluNiowtI1w2R+Cwg== X-Received: by 2002:a05:6402:84e:b0:412:e1ac:391b with SMTP id b14-20020a056402084e00b00412e1ac391bmr441811edz.400.1646759974707; Tue, 08 Mar 2022 09:19:34 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 22/26] usb: gadget: pxa27x_udc: replace usage of rc to check if a list element was found Date: Tue, 8 Mar 2022 18:18:14 +0100 Message-Id: <20220308171818.384491-23-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/pxa27x_udc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/udc/pxa27x_udc.c b/drivers/usb/gadget/udc/pxa27x_udc.c index f4b7a2a3e711..ac980d6a4740 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, *iter; unsigned long flags; int rc = -EINVAL; @@ -1173,11 +1173,12 @@ 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) { - rc = 0; - break; - } + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + req = iter; + rc = 0; + break; } spin_unlock_irqrestore(&ep->lock, flags); From patchwork Tue Mar 8 17:18: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: 550052 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 24DA7C433EF for ; Tue, 8 Mar 2022 17:20:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349102AbiCHRVg (ORCPT ); Tue, 8 Mar 2022 12:21:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348978AbiCHRUr (ORCPT ); Tue, 8 Mar 2022 12:20:47 -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 B0FDD5419A; Tue, 8 Mar 2022 09:19:37 -0800 (PST) Received: by mail-ed1-x52d.google.com with SMTP id q17so25426443edd.4; Tue, 08 Mar 2022 09:19: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=u9SG1/Vum4zcALdcRrS/dZdkcV9xg98RrAHqRdSRgAY=; b=JofGUORGmECmPMRyfeCgpacdZGtX8kTCkXo1V9bqn0kmDI7cVnjjfrga0H5AcMGLTx 3+KEsNvj9PwC5EhLqCWMlFkoNLtz12sZezQDxC4mGa3GqGqAexEYowu8u5/dY3CKZG7M OqkQmiuT/vz4LD9Dak0Vu7gJKjbf90cJXK7hfwLBigxL6sP/O4ZD4WsxgkMOavQ3I+MW r69d7ujJy48OXAAQ7f9vIGu3HKUynY9irfc4+11KDQziuecxQHBvcOOgzYYJHd97qlQO ZwIs6nfSLBFV3f4XPag+WOejrgaDNhYl54YqPoilSOmRvzZCx9Fh53IUCuCokeJGOklI x5DA== 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=u9SG1/Vum4zcALdcRrS/dZdkcV9xg98RrAHqRdSRgAY=; b=I64fz82NZXSjNvhK6x1HUQwvNM0kMXG97yDfxhrnRpjiKRZz9N6tRXMj8fbSmf/iKN H/Efm13Zo0fM4SHbMpnUxh0p9c58VECVGPTMYoAsMp/XoMUNsjnoQca7SOgKcJ/V0fMg 88Alo3LWP4WvxkUFuGv1F2RUqG4DBqu/+iXcnFyIRnLderuMdkFNEzXFSqdQryWD7aFk RkAiBI6GE4CaVf0HxkXy+uDfRq1PBAlJOB1vYUT1ZjQAhJQme2eXqxngwaunJKvElIwM WgfWa6b8Uex1yEmJisEoyxZ+54Cu/VVi0Nr567cYjWnhO96/xSjPhhjxG8mKJrC1egHS QeNA== X-Gm-Message-State: AOAM532SnERl79GUVf6cNakeVwrlHgPdnyaitlS1g/yAUrKJODkwQayz D2qMRmiE5ArUDtgeCw/CApA= X-Google-Smtp-Source: ABdhPJz7WrPed4Zkw2qQCJmozmz22m6kuxxosC22Wx+1shmn5iDSCzwUJUMWXp/gC7tn4lZcajwKaw== X-Received: by 2002:a05:6402:5189:b0:416:63fe:fc6d with SMTP id q9-20020a056402518900b0041663fefc6dmr6718640edd.120.1646759976213; Tue, 08 Mar 2022 09:19:36 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 23/26] usb: gadget: composite: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:15 +0100 Message-Id: <20220308171818.384491-24-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/composite.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 4f7e789c3e07..2eaeaae96759 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -863,24 +863,25 @@ 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) { - /* - * We disable the FDs of the previous - * configuration only if the new configuration - * is a valid one - */ - if (cdev->config) - reset_config(cdev); - result = 0; - break; - } + list_for_each_entry(iter, &cdev->configs, list) { + if (iter->bConfigurationValue != number) + continue; + /* + * We disable the FDs of the previous + * configuration only if the new configuration + * is a valid one + */ + if (cdev->config) + reset_config(cdev); + c = iter; + result = 0; + break; } if (result < 0) goto done; From patchwork Tue Mar 8 17:18: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: 549643 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 3408FC43217 for ; Tue, 8 Mar 2022 17:20:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349030AbiCHRVh (ORCPT ); Tue, 8 Mar 2022 12:21:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349016AbiCHRUt (ORCPT ); Tue, 8 Mar 2022 12:20:49 -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 19C0F50040; Tue, 8 Mar 2022 09:19:39 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id m12so391173edc.12; Tue, 08 Mar 2022 09:19: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=V4vXPVmGTGf3aM5gfb7e+nenL3OxJPCKkBovWpiUsBc=; b=W3Rr+kQiOf7U/zNXKiIybgGxag2KDpokpz3hlzoDsrPnAoo7mSwYsX7FVlpHauDt1D U/U+aXwyG6LbcsGI7sS971Xky8MR5TJ9OvXnOCFi2gyPj2i6o/+a5oKfzN8A6KEbSDqX kwNgoQIltfQqgAmeU40FhKHt3vXGsizsHJIVobm3XraAP6z9uwlwPwGzTJMSy6TIBLHm XrzwrVinH1FLSJExs9eP9NqnLfa3TUamaGQN2T9BpN0itABrjntHycBirIqtZpxmYJf7 QUNdoNEZ3A+z1UOPu2laXXrqD3fE1bj4lB9pEGTE4/YhHtRsuskK4amFL7kf8cd6yd0C DXOw== 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=V4vXPVmGTGf3aM5gfb7e+nenL3OxJPCKkBovWpiUsBc=; b=XMi1RC6MEfLfR4FMBzwPfSOkjHggob2WtwqyDfRz9KSAHJTd/lLOjbGLhwmGceuwx6 cu5bH/5k7SbmGpxOlyXvbkD+3DV9DAn9bxWvnhJe6Dm1VFJADSpUx+YxlN87+hhQ35wy KBFGfUr6xRATrtz3EDv/E8Q26If2yZnMd5UutUAnTDr97/oXRDqUwDC8lY8AF53vBIer BbofVJP0tP9eSeNsmDJu6P+iTxsosEZ1uW5Atj6auLHkcVLiffjWiKOEiDUzpVUNChiN rCDYOtUNkMAviGsH+/OoDaQhmNLwRcHhET9m5VZtfsb5K4eT98XDNW9Ove742ouPl/Zz cL0A== X-Gm-Message-State: AOAM531QhCJKfy8EmvGyDNIFw7TcPOybX6PuChmKR75rnvi7XYNZxywY Fo6QmDNES9Y8Ss5oZnji34g= X-Google-Smtp-Source: ABdhPJxMQ0hlgL52WO6E1BZ4eLdJ/9lm/sh5VABLlk+17MAzErX+vHN8ZSGVSD+UI9O2z+wIwkhTjQ== X-Received: by 2002:a50:9fa6:0:b0:415:fd95:6afa with SMTP id c35-20020a509fa6000000b00415fd956afamr17187529edf.200.1646759977655; Tue, 08 Mar 2022 09:19:37 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 24/26] usb: gadget: udc: core: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:16 +0100 Message-Id: <20220308171818.384491-25-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/core.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index 568534a0d17c..02735b463bb4 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, *iter; 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) - break; + list_for_each_entry(iter, &udc_list, list) { + ret = strcmp(driver->udc_name, dev_name(&iter->dev)); + if (ret) + continue; + udc = iter; + 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(iter, &udc_list, list) { /* For now we take the first one */ - if (!udc->driver) - goto found; + if (iter->driver) + continue; + udc = iter; + goto found; } } From patchwork Tue Mar 8 17:18: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: 550051 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 85A4BC4332F for ; Tue, 8 Mar 2022 17:20:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242789AbiCHRVi (ORCPT ); Tue, 8 Mar 2022 12:21:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348975AbiCHRUu (ORCPT ); Tue, 8 Mar 2022 12:20:50 -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 80E5F19C07; Tue, 8 Mar 2022 09:19:40 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id qx21so40743456ejb.13; Tue, 08 Mar 2022 09:19:40 -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=9K0gcdyqyJc1QtOxbnGCoxSlcO9DFr3Tv4OE16b7cHs=; b=KsliqEO2BmgRd/JUjeCagekkSlvlnEeYkzi1XuFTJZc312pDytb0eYxrKEMnvYkH1X 5nRdaQnkab7c0r9kP8bCinM8AHhLYb4+jR2HSoBumHjNWHbVvPuXA3dQY1GNc0NsDgxz 2r1PahOgdidTf4Mldm1VVfZBp0GNjXWkNdvep/m2da0y4mNRBFmcbVXJNAuEWfYuYp9P Xu2xsoYrJrp9Dcbqv14oZvUZTO6nz7cVXz3Fky5Mt3NvcuKOrvEwcMOXl1Poc0ct0AIB laB6aMGnzn/9HFgXkbVf1jJMY0CNHl4+h9NIIx9GVtkjjzf33RDEHgtbaF/4XaJol/nj /peQ== 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=9K0gcdyqyJc1QtOxbnGCoxSlcO9DFr3Tv4OE16b7cHs=; b=J14wVZY/rDAc1q/qyejGtVXze5bB+V+9npGDlsS7lKzbCPR0Lf78PoHXK7DufoyY5R iDYEcE2lxf1jUrSpMDhz98hIRm9Qo2ilvbd7VH8EyqJJF72qXQRQGHjgnu0/Mux9GkJG oJXGs022w8FFfYD7rnMyvdr9gajl9pjlIen3mjRyCXNpRJw8dLqZH9jAnciONCRJWp4j VGZ2Aip3E0EJxbA4Kyeu/pLMt3ZEgWXa0mR6XMEd/jXUeKB/liqA8EP5u/rIFf44hLs2 u+3NaPaIMr7EmlQd1c2D1SgAWbd3UdgDFA/luVG1nbNQN8324l+Y0hv9lCEsLOwwvyCx b57g== X-Gm-Message-State: AOAM531JyshlifBdXCTR8R8rxw2Ixk/0S0lCQ7+sbGLGjxWZIzLPQwjk zQd2GgHpDmZAT7xCMqcOrmw= X-Google-Smtp-Source: ABdhPJzROPf0on8GO23L49XUIf01Xp7An6s1Bg7AFDWIE/J91fVVH3cYCteWptRh8cz08W/V4nh/LQ== X-Received: by 2002:a17:907:168a:b0:6da:9167:47dc with SMTP id hc10-20020a170907168a00b006da916747dcmr14227765ejc.126.1646759979025; Tue, 08 Mar 2022 09:19:39 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19:38 -0800 (PST) From: Jakob Koschel To: Greg Kroah-Hartman Cc: Jakob Koschel , linux-kernel@vger.kernel.org, Linus Torvalds , Felipe Balbi , Joel Stanley , Andrew Jeffery , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Cristian Birsan , Al Cooper , Li Yang , Vladimir Zapolskiy , Daniel Mack , Haojian Zhuang , Robert Jarzmik , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , linux-usb@vger.kernel.org (open list:USB GADGET/PERIPHERAL SUBSYSTEM), Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH v2 25/26] usb: gadget: dummy_hcd: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:17 +0100 Message-Id: <20220308171818.384491-26-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/dummy_hcd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c index a2d956af42a2..35aec8e7fc73 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, *iter; if (!_ep || !_req) return retval; @@ -763,13 +763,14 @@ 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); - _req->status = -ECONNRESET; - retval = 0; - break; - } + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + list_del_init(&iter->queue); + _req->status = -ECONNRESET; + req = iter; + retval = 0; + break; } spin_unlock(&dum->lock); From patchwork Tue Mar 8 17:18: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: 549642 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 EC05AC433FE for ; Tue, 8 Mar 2022 17:20:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348958AbiCHRVu (ORCPT ); Tue, 8 Mar 2022 12:21:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348982AbiCHRUw (ORCPT ); Tue, 8 Mar 2022 12:20:52 -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 0D71B54684; Tue, 8 Mar 2022 09:19:43 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id hw13so40608497ejc.9; Tue, 08 Mar 2022 09:19:42 -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=aqxR4IBXZYNnThtWgqyRIE5yTni2priLEgPy6w83o+Q=; b=kgTAP8XGpVlUPOF/8Z1AY41u1JN3iLbKcygsYP+oBsccD1GWF+nAWpghgMyp72H+Qj L1y7kTy86rEUTIK2dNmSSFN72ROpe1dz8CaETW1pnHrZoVy1fShKLMGoRpWR1EylKUwd z5GaJzt8eGncFkPGiVdEaYegad+cPaKy842xY9ILXR81ZlU7w4U8+R93HfiduKFTEylV FdylLD9bjZURw96QJo6jao6VG2uLtmK2OakXe6URFFqCWnbG/ps4PYJfyYjtg1VE1Pht 7gpoFEi2mm5Fhmnxt0WuyM2l3yht46dRtZZtGZukOpAEY495gcQgCo6LGhMrfVNTH+8U rHNA== 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=aqxR4IBXZYNnThtWgqyRIE5yTni2priLEgPy6w83o+Q=; b=DLn05XSWmJ98PP5g8FanUH41ysvbfG+qoiaQbgQRRLZsqt3GZj9PZbV2nPDF1qErrF fMBw+75famDQn4ogVl5ikYvCvk0jSwI545paLNPTgOK919L5cT8tQSnOtUO+5WijPlbY tmM1+OQq8xoN9/uCYtCLzuCACMBtycpdmHAAjeVj+0M3VgPlm8OexxjrM6ZIcBqJ8eAr /W7g80W2w/SqmCjpm1XMOkHHjSQD8BZcAh7c/H9iglBC739zoAQHrYTrsVnkLqzM7o9w 7YFMws74sXmVfZGffZ1Ts0I7+PolbLP6XvnsAU3ean9vKOAdzxHC9WwdlKRIhOLiTWwy 5jhQ== X-Gm-Message-State: AOAM5334BC8LEUYzkyoYFoxgChcc7Ox6naG9Qr2vwjuHsLieRQeEe9uv Ue76C+nhx2MpvpgRV/Xf95k= X-Google-Smtp-Source: ABdhPJz0t2lt1ecx6E29WZrWRYHg3uEddwUclWaXx43v3UwYgxUGqsHyyVae+6Yj68CK4uozjNPtvQ== X-Received: by 2002:a17:907:6d0e:b0:6d7:c85:5bf5 with SMTP id sa14-20020a1709076d0e00b006d70c855bf5mr14214634ejc.31.1646759980757; Tue, 08 Mar 2022 09:19:40 -0800 (PST) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id rv11-20020a17090710cb00b006d5c0cd5e0dsm6085044ejb.82.2022.03.08.09.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 09:19: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 v2 26/26] usb: gadget: udc: s3c2410: remove usage of list iterator past the loop body Date: Tue, 8 Mar 2022 18:18:18 +0100 Message-Id: <20220308171818.384491-27-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220308171818.384491-1-jakobkoschel@gmail.com> References: <20220308171818.384491-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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]. Link: https://lore.kernel.org/all/YhdfEIwI4EdtHdym@kroah.com/ Signed-off-by: Jakob Koschel --- drivers/usb/gadget/udc/s3c2410_udc.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c b/drivers/usb/gadget/udc/s3c2410_udc.c index e3931da24277..c6625aeb7bca 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, *iter; dprintk(DEBUG_VERBOSE, "%s(%p,%p)\n", __func__, _ep, _req); @@ -1277,13 +1277,14 @@ 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); - _req->status = -ECONNRESET; - retval = 0; - break; - } + list_for_each_entry(iter, &ep->queue, queue) { + if (&iter->req != _req) + continue; + list_del_init(&iter->queue); + _req->status = -ECONNRESET; + req = iter; + retval = 0; + break; } if (retval == 0) {