Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp25701pxb; Tue, 12 Apr 2022 15:47:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPpOjMsMWFiGl8iEcQZHEMk3qfDGetkRpU6zV/WpqQBz88tyJFNj8VEViZV2CUDIm7gmcp X-Received: by 2002:a17:902:ce05:b0:156:a7f7:aae1 with SMTP id k5-20020a170902ce0500b00156a7f7aae1mr40514068plg.166.1649803656959; Tue, 12 Apr 2022 15:47:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649803656; cv=none; d=google.com; s=arc-20160816; b=gVdZX/7BGxE45y/ABQQYsnBLhGaADUCbievzgwB7UrnB8Pb6a5o9uzKQWchCSt1/2H XKvQfFiNiCZH+UhXc2LDKgQDwT+3Eq1QVhS8WXLetc35zzTGK7HFvRAkYw1HyPE4/LuG FXP6rZZc4BZFT4f6grjRQfa7sSY6jtBX3tKsiD+tKaTWlZKm8CespXDvCesKGDiOtj9v PUohsVheNZ8huh1Z5T8tQzhLhSpmn/msanuI0Sg0YAI4T8QWEieXvdx97xKZBoCZrXXg A3iZyKZH1UBrDo8kSOPcK5LDwEd+5r88ZCZJ94/zCI4MHqHkHB+Riz0Ctk3tZcTAFdML jlKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dCmksJmPxgakgPcETkyiMkdEpAIfPO8dTB6JgwQ/+0c=; b=EKffupLcz9kyDCgUmLofShqAsO0Srzf6oVQ9hKC5R46ax/ZfBupMqXl7htYoc2m7j/ agiBH+c9wGFYImnoAUlrZHTNVkgy3AeQxHd20v9VYU02oYybhWHcczlx3ml5p0F2TlAC +8WzHx/w6sxcRTzpc/2DBycx5Upz6hm1kwYNimBT8v5NOTzG1jdS8YmVS+RDwzc+2Ymv sXqkU0kO4KvF+QhdvMho3K9t3NhaGYGazTiQ6BfWAr6qgZEDQMMogkn7B0drhBmnuy1i qoxeA634fgWfU+NuB/cb98zDyvUDxltXMbFxagjMdnQPWteBSNB3icqDDVyhsRTwhuyI T18A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fJz20MHN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l20-20020a63da54000000b003864fd7c214si3761512pgj.689.2022.04.12.15.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 15:47:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=fJz20MHN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 81BD21BA47E; Tue, 12 Apr 2022 14:28:42 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243527AbiDJUhU (ORCPT + 99 others); Sun, 10 Apr 2022 16:37:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243068AbiDJUhP (ORCPT ); Sun, 10 Apr 2022 16:37:15 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D1BC4ECF0; Sun, 10 Apr 2022 13:35:02 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id z12so3442116edl.2; Sun, 10 Apr 2022 13:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=dCmksJmPxgakgPcETkyiMkdEpAIfPO8dTB6JgwQ/+0c=; b=fJz20MHNwDvsBXdmgdMPNyq04BZ5BUG60QpxolftSlFksOd7su6HQLoU6Ym3gzUS9Z 1HOHAI1W86fYaCzaxUN5sXZRzTzF/FgAhUMtk7w7n4SKYTDfggk4U2NXEHuuhBg5bOQj 7AmYBCt6RZKmk/JrDlUwsJpoUULpi+QFAllfEIz2JBYO/eXqDK3Iev7FQY9dKcvA4Mmi tQGnUFhaplfYowHS0ggxLJH7BKaETYZLgXmFDsdvnDdMysaS0fSWOExFy96UIba2+vWu mz4aSQmoRlql8Scvd4xNgNcCvlcKYqi0CPXxIMHdzILmeexpscOm7rOOgg8pNpvJhqYL im3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=dCmksJmPxgakgPcETkyiMkdEpAIfPO8dTB6JgwQ/+0c=; b=g//ZVmU7j2RwvxTjh7bHgP8TxPxVphr+3qIWFIpUgOae36UjsY7RuOsGobb9nTUgAd kQtxrRhnlPm03UOR5GcdDQW+Im9CJsZBqk+bEtiMYvhvEADXRxs/NGuxfSGzwE4leD78 uOp0GsEeThTctTRe6oHBGauKicygVZjGGPRt8K3O0RDD3widb6MmS/PUdB6n6ZEDME3T nAUMc1vP9up7biLBuAxClE/e5JIFr3/Rq0swV8SxaGXqftccZzqM9cBDFsO/Z7hPzW7T 1tEezlQFDUf0XwNa6ZuFMAYLOI8YTmJt+9JLB7jWTocCJJ+oC7xErRvdW+mLnuUnISXm wq3Q== X-Gm-Message-State: AOAM532Ny2lIaSQW6fR7UP9KcIgMsTTVApUEmQ+H/m2VuS50hCUgtJGS QWDGTEC5gnbMPo9DPun56Ow= X-Received: by 2002:a05:6402:34b:b0:41d:7026:d9e3 with SMTP id r11-20020a056402034b00b0041d7026d9e3mr7280900edw.168.1649622900513; Sun, 10 Apr 2022 13:35:00 -0700 (PDT) Received: from skbuf ([188.26.57.45]) by smtp.gmail.com with ESMTPSA id u25-20020a170906b11900b006e08588afedsm11183676ejy.132.2022.04.10.13.34.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 13:35:00 -0700 (PDT) Date: Sun, 10 Apr 2022 23:34:57 +0300 From: Vladimir Oltean To: Jakob Koschel Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Andrew Lunn , Vivien Didelot , Florian Fainelli , Lars Povlsen , Steen Hegelund , UNGLinuxDriver@microchip.com, Ariel Elior , Manish Chopra , Edward Cree , 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 , Xu Wang , Netdev , LKML , Linux ARM , linuxppc-dev , Mike Rapoport , Brian Johannesmeyer , Cristiano Giuffrida , "Bos, H.J." Subject: Re: [PATCH net-next 02/15] net: dsa: sja1105: Remove usage of iterator for list_add() after loop Message-ID: <20220410203457.3las4i3qcmaitsjt@skbuf> References: <20220407102900.3086255-1-jakobkoschel@gmail.com> <20220407102900.3086255-3-jakobkoschel@gmail.com> <20220408114120.tvf2lxvhfqbnrlml@skbuf> <20220410110508.em3r7z62ufqcbrfm@skbuf> <935062D0-C657-4C79-A0BE-70141D052EC0@gmail.com> <20220410200235.6mtdkd2f73ijxknn@skbuf> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.7 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,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Sun, Apr 10, 2022 at 10:30:31PM +0200, Jakob Koschel wrote: > > On 10. Apr 2022, at 22:02, Vladimir Oltean wrote: > > > > On Sun, Apr 10, 2022 at 08:24:37PM +0200, Jakob Koschel wrote: > >> Btw, I just realized that the if (!pos) is not necessary. This should simply do it: > >> > >> diff --git a/drivers/net/dsa/sja1105/sja1105_vl.c b/drivers/net/dsa/sja1105/sja1105_vl.c > >> index b7e95d60a6e4..2d59e75a9e3d 100644 > >> --- a/drivers/net/dsa/sja1105/sja1105_vl.c > >> +++ b/drivers/net/dsa/sja1105/sja1105_vl.c > >> @@ -28,6 +28,7 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, > >> list_add(&e->list, &gating_cfg->entries); > >> } else { > >> + struct list_head *pos = &gating_cfg->entries; > >> struct sja1105_gate_entry *p; > >> > >> list_for_each_entry(p, &gating_cfg->entries, list) { > >> if (p->interval == e->interval) { > >> @@ -37,10 +38,12 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, > >> goto err; > >> } > >> > >> - if (e->interval < p->interval) > >> + if (e->interval < p->interval) { > >> + pos = &p->list; > >> break; > >> + } > >> } > >> - list_add(&e->list, p->list.prev); > >> + list_add(&e->list, pos->prev); > >> } > >> > >> gating_cfg->num_entries++; > >> -- > >> 2.25.1 > > > > I think we can give this a turn that is actually beneficial for the driver. > > I've prepared and tested 3 patches on this function, see below. > > Concrete improvements: > > - that thing with list_for_each_entry() and list_for_each() > > - no more special-casing of an empty list > > - simplifying the error path > > - that thing with list_add_tail() > > > > What do you think about the changes below? > > Thanks for all the good cooperation and help. The changes look great. > I'll include them in v2 unless you want to do that separately, then I'll > just remove them from the patch series. I think it's less of a synchronization hassle if you send them along with your list of others. Good luck.