Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp18175pxh; Thu, 7 Apr 2022 21:29:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLNvD66VrZfIy7uQBpV0/hBU51ery1skbRKb9sUIlUugj5z3xeBEa57+d0Dign+KAjl6T9 X-Received: by 2002:a17:90b:1b52:b0:1c6:b689:813d with SMTP id nv18-20020a17090b1b5200b001c6b689813dmr19331828pjb.186.1649392145728; Thu, 07 Apr 2022 21:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649392145; cv=none; d=google.com; s=arc-20160816; b=pS8iK7XwOX47QkWYKPEb/KE35ZZiQlUpWlrX/i2yRX/MRy7UOgr/pdBsbEOjWmx5bq ukTQyHEkwmSd+aunVu9HUpR+bjy28tOed81XoLkzADHniAcpiQzGur0MKgH0h3gLb8oF otVhQU7Cv+7vVi/GvgZ2f0xtCOf53diHP8A6KCv1HssUQYdyXwHd0WH3eg8ogMTo8Rdh gVlt+0eFhF1gKr9nrJFBrS12o5zzoTKKeV0m2EKJcjAdQUcVBqna+YEQOROtyxJ9tBQV jygvThXAsg7O5RRoU3kKfbRImlOFLVeTwsFqPfwZJ7Gff932DeAo/KCKCY/2TO4ZYTAF E5tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=yMjAzfQQ9y3tKmpmxLGsu159FGsG5wF6e8oll5ervFQ=; b=P2F6WepTzi/dPKHsu/IY07tAppO795bmoeY8XzDUdOrqkyaW/JeYGXmlTkxz7GOGGP qwQ1emSVUav1+Bgfdfi3oroy6IYuYYeDTbmqRr/nJC1zggIKfMXTMN6PkIMQFieQT4UK 7ANJhm2KsBzr6Hztxjl4QwQcLN9NZCO4C4pHu70bvWODwGqXQ4y+LqizKd0S1/+81cHx cp6KnntJYeAmg4f/Ile1hxVctAa676IvD+0pZgO9VUk7t9InwnzeEzaTBEQ/z6CeILdj M0c8Q8fqb1RUwoq9Oy92bWJhWWeLLTXXi7VGUTQreHNbOlwbyLJLyrdY2ngG6rW3p71P fStQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=avEXtVrk; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h12-20020a056a00230c00b004fa8ece95b0si70359pfh.85.2022.04.07.21.29.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 21:29:05 -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=@kernel.org header.s=k20201202 header.b=avEXtVrk; 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=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 53538CFB8D; Thu, 7 Apr 2022 20:54:46 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234018AbiDHD4k (ORCPT + 99 others); Thu, 7 Apr 2022 23:56:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234010AbiDHD4f (ORCPT ); Thu, 7 Apr 2022 23:56:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3050CBE4C; Thu, 7 Apr 2022 20:54:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 15B80B829AE; Fri, 8 Apr 2022 03:54:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FD55C385A1; Fri, 8 Apr 2022 03:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649390068; bh=XvrZjZaX5Rsi5fiZFoDR7A0z44p/01oSQz1BX2ODyvU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=avEXtVrk7mOyW8zohyzfG6CeVAW9WHmglJH2zFNO6BqivVAiwRFXM5FysYbfpSW4R e5ioNTKU9dR9CdSfVo/qzoEX+KFzJXpGKeUC7RYWphXdJ9lD7QEgvw1cEHhAK3riim SfLqUUEiyZ6Fo9fMpvbleZcmaOnWtrU+CsAVL3b/ftZoe3QS1owYNeov9z652aNwns +dhbMjxfJFqASqlpcBfHfh/dNAHNoXw1FYbDqttp1G+Tba1An+xtmjAldSlNV81Un0 hXlyPc0jm4HYBSy2zICqZdHsaMx79AWrW1iGEJpX+m85MDo32q6JDwBzIWVYqdGVM3 4k9iubEHtRGQg== Date: Thu, 7 Apr 2022 20:54:26 -0700 From: Jakub Kicinski To: Jakob Koschel Cc: "David S. Miller" , Paolo Abeni , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , 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 , 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." Subject: Re: [PATCH net-next 02/15] net: dsa: sja1105: Remove usage of iterator for list_add() after loop Message-ID: <20220407205426.6a31e4b2@kernel.org> In-Reply-To: <20220407102900.3086255-3-jakobkoschel@gmail.com> References: <20220407102900.3086255-1-jakobkoschel@gmail.com> <20220407102900.3086255-3-jakobkoschel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, 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 Thu, 7 Apr 2022 12:28:47 +0200 Jakob Koschel wrote: > diff --git a/drivers/net/dsa/sja1105/sja1105_vl.c b/drivers/net/dsa/sja1105/sja1105_vl.c > index b7e95d60a6e4..cfcae4d19eef 100644 > --- a/drivers/net/dsa/sja1105/sja1105_vl.c > +++ b/drivers/net/dsa/sja1105/sja1105_vl.c > @@ -27,20 +27,24 @@ static int sja1105_insert_gate_entry(struct sja1105_gating_config *gating_cfg, > if (list_empty(&gating_cfg->entries)) { > list_add(&e->list, &gating_cfg->entries); > } else { > - struct sja1105_gate_entry *p; > + struct sja1105_gate_entry *p = NULL, *iter; > > - list_for_each_entry(p, &gating_cfg->entries, list) { > - if (p->interval == e->interval) { > + list_for_each_entry(iter, &gating_cfg->entries, list) { > + if (iter->interval == e->interval) { > NL_SET_ERR_MSG_MOD(extack, > "Gate conflict"); > rc = -EBUSY; > goto err; > } > > - if (e->interval < p->interval) > + if (e->interval < iter->interval) { > + p = iter; > + list_add(&e->list, iter->list.prev); > break; > + } > } > - list_add(&e->list, p->list.prev); > + if (!p) > + list_add(&e->list, gating_cfg->entries.prev); This turns a pretty slick piece of code into something ugly :( I'd rather you open coded the iteration here than make it more complex to satisfy "safe coding guidelines". Also the list_add() could be converted to list_add_tail().