Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp679439pxp; Wed, 9 Mar 2022 10:22:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHpdwvJb8kdI9lyXGOeKOKdcIuxPNvLGnKMaAXCieCq/gU9ecf1x5ng69ciwkxiF5yPfcF X-Received: by 2002:a37:9346:0:b0:67b:128f:4696 with SMTP id v67-20020a379346000000b0067b128f4696mr647969qkd.442.1646850127604; Wed, 09 Mar 2022 10:22:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646850127; cv=none; d=google.com; s=arc-20160816; b=fNaXQ6McqaBW0kFBHFVl1En4/DuHdFq6O63TJ4Nr39EFY9xMzDxGnpGR++yhSZmD28 OliSbg31Rkl0gGfUo61z5DYEpn3usHgQpmOkoks71PUkhHzL5Rs42rnANZLlEuWAVLx0 n4+2TgDuB1FE6yAU2X3cOddB7O3zF2vZywkDejYHZIOyPdJVoQFNjpquaOjyXgFY1eKd WuG8Ug6zXELEc7IVDjbS13orDVHTlUsW6l+d2boeY8AI+Mj2+vDTdr2fXYimUoJRjwP6 0kJ0MyJshANGXT21IOrA2w6YnHFTmnznzqKnLn8G2SffTmUs3AWrGtPTEM+RJTo5rtUV 4NOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ywWEngNkae6mKxGv+1cfuhQRhz77SMjtBbNBkeG8nw8=; b=br49p35DadmkQARrdy7hnDNhFYcF5grnF5ed/30YHu5qgsoIOv4PcMZqtSk5hzTZJg +1pZ3IS+IPzcVgO7Y6L4ND2pWlZqkFLAPU5Rta3/8DpnybBaQ1uSxOhjaEn/F924qUXX neTzS/cOJhrlFuPaeZA62UscXVxsADtj13aqykyvjgHjkK128Gtur/ZtFz6/h6D3/wjk Tv9qFypK5NYusfeVcV/OI3JF492GGEgeFVOpFCCkzIJ3ZnjPn8mTqmsY2Hs7cD5AymWE Of/nY439Rh56LsuuhRan7dQjnCf0hJdnJI7dogq96HFZ4Lyv1XY/9mTwRnZjocKrgQvD GUxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=opxAkGKE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d7-20020a05621421c700b004352e0aa5ecsi1325545qvh.484.2022.03.09.10.21.28; Wed, 09 Mar 2022 10:22:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=opxAkGKE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235897AbiCIR5k (ORCPT + 99 others); Wed, 9 Mar 2022 12:57:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235389AbiCIR5i (ORCPT ); Wed, 9 Mar 2022 12:57:38 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4FDE5FB6 for ; Wed, 9 Mar 2022 09:56:38 -0800 (PST) Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 61F433F60B for ; Wed, 9 Mar 2022 17:56:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1646848594; bh=ywWEngNkae6mKxGv+1cfuhQRhz77SMjtBbNBkeG8nw8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=opxAkGKE+ANGbqE49XImtNzXdL7bDDrHuO1RdyspQC+zv1qhaIIyXgBbuwyDwB73H qnW+8+FNZ/bmrxXH6RmWuODDskvbsW6eGzoc5lhuHJvnmziHW4n11RTJOWXbvzr+4x xWo0xd8vdVnODOQMcClcLBBN9pA5wKJ5SzEpPG7H5ABfoB5lpgUcy090leozq7kGBJ gbIrINqtVVsk5X8aeHXg1LncpeYCN+NSL4Cz9ov+aH6ylU6GkYEUtzUg52J1VdX0UH xKWzv6bFoboi31uCzipgbHw+O6qV5XiDp7mhb7QRiy0IJQb6plEaLA6Wxc2ma2s/H0 m165q81/QzTBw== Received: by mail-ej1-f69.google.com with SMTP id go11-20020a1709070d8b00b006cf0d933739so1714725ejc.5 for ; Wed, 09 Mar 2022 09:56:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=ywWEngNkae6mKxGv+1cfuhQRhz77SMjtBbNBkeG8nw8=; b=cKyoX4+wEV4lOdWkQQTQjpMnsOvJ17M/S31L5ccnvi5ojEFwWHRwJEkJTI09Rs9Dfp D76n5Sy03RZCMYL8gCla40Kd9COTiWgkSJDSElC7A98lu1vHCtageqxQv+fdJxRYJPGV DAI5pXQvDLn+Uv9ZGYUa/bmkQ1jM5efiN8jcMntlymKrk1s7D8Erh39st5zuyub1PXd2 lmYirFLkVdcSbzwgAPqSOk/G8xJwT9r8I1UvJABs1Zgc6ino6eu0I6UdBl4qamLDp486 v6Z908ik4N1o46sk3AoK5B0qx+RBlByigtwLBmacN9quMaaHajZ3I2uYCnsCLFBLnP3T KYIQ== X-Gm-Message-State: AOAM533E23wTFTUcrjSjtOMO+T4XJA7GkkFdfk2XcEjz2vLKuloT4jw4 S1Soc3zhQ3+vz9IszEWPCZ2nW1vQi41yCn7m2idMwTEpXGrlSeBjst+i3IB9oJPCG9XkMVzr1+d GZpFWm+ds9sX+v9X7UU95v3I8227z3QYurbc9Dy9lEA== X-Received: by 2002:a17:906:69d1:b0:6ce:7201:ec26 with SMTP id g17-20020a17090669d100b006ce7201ec26mr866310ejs.105.1646848593329; Wed, 09 Mar 2022 09:56:33 -0800 (PST) X-Received: by 2002:a17:906:69d1:b0:6ce:7201:ec26 with SMTP id g17-20020a17090669d100b006ce7201ec26mr866289ejs.105.1646848593018; Wed, 09 Mar 2022 09:56:33 -0800 (PST) Received: from [192.168.0.144] (xdsl-188-155-174-239.adslplus.ch. [188.155.174.239]) by smtp.gmail.com with ESMTPSA id h8-20020a50ed88000000b004160630c980sm1095553edr.62.2022.03.09.09.56.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Mar 2022 09:56:32 -0800 (PST) Message-ID: <6867439a-b995-86e7-6136-bcb8709eeb90@canonical.com> Date: Wed, 9 Mar 2022 18:56:31 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v2 14/26] usb: gadget: s3c-hsudc: remove usage of list iterator past the loop body Content-Language: en-US To: Jakob Koschel Cc: Greg Kroah-Hartman , Linux Kernel Mailing List , 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 , Alim Akhtar , Thierry Reding , Jonathan Hunter , Michal Simek , "open list:USB GADGET/PERIPHERAL SUBSYSTEM" , Mike Rapoport , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." References: <20220308171818.384491-1-jakobkoschel@gmail.com> <20220308171818.384491-15-jakobkoschel@gmail.com> From: Krzysztof Kozlowski In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/03/2022 18:36, Jakob Koschel wrote: > >> On 9. Mar 2022, at 18:25, Krzysztof Kozlowski wrote: >> >> On 08/03/2022 18:18, Jakob Koschel wrote: >>> 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; >> >> You have in the loop both continue and break, looks a bit complicated. >> Why not simpler: >> >> if (&iter->req == _req) { >> hsreq = iter; >> break; >> } > > Ultimately I changed this based on the feedback from Linus > (Link: https://lore.kernel.org/linux-kernel/CAHk-=wheru6rEfzC2wuO9k03PRF6s3nhxryCAnwR5bzKwPV2ww@mail.gmail.com/). Not cleaner to me at all, but it's all personal opinion. :) >> >> ? >> Less code, typical (expected) code flow when looking for something in >> the list. Is your approach related to some speculative execution? > > no relation to speculative execution. > > I have no preference for one over the other, so I'll just change it to > however it is desired. > > It would just be great to have a (somewhat) consistent way so I can prepare > the rest of the patch sets accordingly. > Yeah, I understand. The code itself looks good, so: Reviewed-by: Krzysztof Kozlowski Best regards, Krzysztof