Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp42368pxh; Thu, 7 Apr 2022 13:24:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm822eF7igE97NJHnN9em7c4hTFoytZnXMyGV+IumahU1MHAtSNS99NppX+V2w7vJq9VYq X-Received: by 2002:a63:cc53:0:b0:372:7d69:49fb with SMTP id q19-20020a63cc53000000b003727d6949fbmr12875447pgi.21.1649363078490; Thu, 07 Apr 2022 13:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649363078; cv=none; d=google.com; s=arc-20160816; b=MAqzeaSqS89PRZ/zL4yOKiz8T2Xqe1ztjPzcOQtAYaX/ZIrwFpQ1EOq2kkR/yg7MJG 0vlRWVrtql/9NJmkpxuSDjmur2nR/+CFMnXeOh8jHmtN+lguUcAmaU9Fhc6KXQ49uYVo wDLXNxbWtgK1Lup9uIcXHbsaP+Lwm3g02hHzwk5ZNQC3RHrYqCJ8MFIhxeDVWener/95 cP9FYqxPj94QQrTvd1YUEp5SOa7wbTW4RGl+FrMtuZ39fksiyWf/cxbwIuI1EF1WLh/N JXFCZQU2W66R5VKRWQOjpUjPOwM7o6Ftx2vrq1RlxGO3HK3irTmhJJsvfRMEaWC11i3U fSVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=Qf5/HY0H/HARlpQawjWcubI38eU259kawMq8gp9O7d4=; b=o/UZkPw6RMCiQKdFr16p/ie/FR6mQU3c7K4u0xw6OAoqZhtJRUNBej55UF0SbZ16Il uybFLDPkCNdTKOvDrrLPBM827e+Yp8/gAwqXQigSjITju9sjeODoc+Mq6jYTXDD9jts/ OywZjMbhepfLjA2XR7ms0QtJAhIL/kFs0BZaDD7TdgKp/9NuWXaM8oQ3cLoZV8CvTAEc kLdYowf/rIYI5Jt49LuROCKS1uiWTQC8Bmf0UP/XwoSqRwTRFmLUNBi0MMYZDawu3FXt i7viFXZ4Kufg8a7UtGmnJFEEUgXgIKN4QPANf89BAOk2+qroXiV1QuFjBq3H9vPRxxG/ arEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CrkVJRLO; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id z14-20020a056a00240e00b004fa3a8dffb9si20022480pfh.112.2022.04.07.13.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:24:38 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=CrkVJRLO; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AB14634DD21; Thu, 7 Apr 2022 12:40:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346471AbiDGRoY (ORCPT + 99 others); Thu, 7 Apr 2022 13:44:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231331AbiDGRoW (ORCPT ); Thu, 7 Apr 2022 13:44:22 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A67B22834A; Thu, 7 Apr 2022 10:42:21 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id j12so8951642wrb.5; Thu, 07 Apr 2022 10:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Qf5/HY0H/HARlpQawjWcubI38eU259kawMq8gp9O7d4=; b=CrkVJRLO1aSJixV9DWKUTF746y41oFcj/ZYQXCMA93sWiB0r8cbHO/f8LZz8KS6V2R VtJYpBNgDsp6YUKM35f2uF3N+8gfMhpVgeHmhzuz8xy4T8pCvh4xoKIQ25X6AicMAZXP deImoshAMsKtF6YC9AZ2M7IJUaUdxIiycCgtpArV5rA0mTPv8LpJEcJyarvYcnZXmNCI aWlfhIlk0mpOrWQ6OdxS5X8MjD75utFVj5Sl/xPB855dp78ch/LkHjf2soCCgGydwfVJ cTIojrIudwVz04FEA14NfrVFmBYZG7vKl9ICFrjbOEbVg9rmja7sZ7v3ms1J2iW6OXWv jt3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Qf5/HY0H/HARlpQawjWcubI38eU259kawMq8gp9O7d4=; b=7qi7tCz7JqzOUKHbGVwAmoXq7ilh7nC0G7LKmc9lF8tsOysF7stit+/K9GUCHtkMaw wD93RyXmGooAdt0zLE9rd23OK2tShHUQOgGyVigLPOP1v3dVeNAg4thLVXtXDEw5rnC7 +RAWU0G38rm49LrSPrm2NDFoKCyXRnW9pauqVE7595z86BDH6ThQGNy1PvPtCl5lPnJB Jk+J5amPSGX7FgF+3XZRFkZXSxzKfWw1ybkYSgqMw9sTGQxeWw7HUNQ/i/XGNR68F7ks 3GmZtmfujAIrET9f2y1Xzlu+VY2GS17NxUPYV7T53Z1ZSpOIXG3ISLjC5rVvUKPwha7l yziA== X-Gm-Message-State: AOAM531nls20aIahsE1S/drhLWAagcYpTVRewh/N6nIuXB41hd3aUWOh MbZZ+P43s8t+kl2zGDb5gnI= X-Received: by 2002:adf:d222:0:b0:206:17ba:5f76 with SMTP id k2-20020adfd222000000b0020617ba5f76mr11454903wrh.484.1649353339722; Thu, 07 Apr 2022 10:42:19 -0700 (PDT) Received: from [192.168.1.122] (cpc159313-cmbg20-2-0-cust161.5-4.cable.virginm.net. [82.0.78.162]) by smtp.gmail.com with ESMTPSA id y6-20020a05600015c600b00203fa70b4ebsm21873677wry.53.2022.04.07.10.42.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Apr 2022 10:42:19 -0700 (PDT) Subject: Re: [PATCH net-next 11/15] sfc: Remove usage of list iterator for list_add() after the loop body To: Jakob Koschel , "David S. Miller" Cc: Jakub Kicinski , Paolo Abeni , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , Lars Povlsen , Steen Hegelund , UNGLinuxDriver@microchip.com, Ariel Elior , Manish Chopra , Martin Habets , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Jiri Pirko , Casper Andersson , Bjarni Jonasson , Colin Ian King , Michael Walle , Christophe JAILLET , Arnd Bergmann , Eric Dumazet , Di Zhu , Xu Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Mike Rapoport , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." References: <20220407102900.3086255-1-jakobkoschel@gmail.com> <20220407102900.3086255-12-jakobkoschel@gmail.com> From: Edward Cree Message-ID: <4520e9c5-8871-b281-f621-ac737e64333b@gmail.com> Date: Thu, 7 Apr 2022 18:42:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20220407102900.3086255-12-jakobkoschel@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE,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 07/04/2022 11:28, Jakob Koschel wrote: > In preparation to limit the scope of a list iterator to the list > traversal loop, use a dedicated pointer to point to the found element [1]. > > Before, the code implicitly used the head when no element was found > when using &pos->list. Since the new variable is only set if an > element was found, the list_add() is performed within the loop > and only done after the loop if it is done on the list head directly. > > Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] > Signed-off-by: Jakob Koschel The commit message doesn't accurately describe the patch; it states that "the list_add() is performed within the loop", which doesn't appear to be the case. Also it seems a bit subtle to use `head` as both the head of the list to iterate over and the found entry/gap to insert before; a comment explaining that wouldn't go amiss. (I'd question whether this change is really an improvement in this case, where the iterator really does hold the thing we want at the end of the search and so there's no if(found) special-casing — we're not even abusing the type system, because efx->rss_context is of the same type as all the list entries, so ctx really is a valid pointer and there shouldn't be any issues with speculative accesses or whatever — but it seems Linus has already pronounced in favour of the scope limiting, and far be it from me to gainsay him.) -ed > --- > drivers/net/ethernet/sfc/rx_common.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/sfc/rx_common.c b/drivers/net/ethernet/sfc/rx_common.c > index 1b22c7be0088..a8822152ff83 100644 > --- a/drivers/net/ethernet/sfc/rx_common.c > +++ b/drivers/net/ethernet/sfc/rx_common.c > @@ -563,8 +563,10 @@ struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx) > > /* Search for first gap in the numbering */ > list_for_each_entry(ctx, head, list) { > - if (ctx->user_id != id) > + if (ctx->user_id != id) { > + head = &ctx->list; > break; > + } > id++; > /* Check for wrap. If this happens, we have nearly 2^32 > * allocated RSS contexts, which seems unlikely. > @@ -582,7 +584,7 @@ struct efx_rss_context *efx_alloc_rss_context_entry(struct efx_nic *efx) > > /* Insert the new entry into the gap */ > new->user_id = id; > - list_add_tail(&new->list, &ctx->list); > + list_add_tail(&new->list, head); > return new; > } > >