From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 077CAC433EF for ; Fri, 8 Apr 2022 23:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:References:Message-Id:Cc:Date: In-Reply-To:From:Subject:Mime-Version:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gGjQotm3rEntqKGSGPX6L4ePSGKagt8EnZKWL0CkivA=; b=VBTWqBgeiozDXg BzKdVMnBU7i5qEXe+ep8gSXQ056e8a7E/lyNgQk6zR6xR5O9l8p3fVPHSaolOccjpN4O4CqLzzxcR gIO552qIdQENUp2hky8WRVShShT7nNewTWak06DRaSK17CUoOe91SOdrP+5ocVjMLv46vlAQWiiho dnI31I+VbYMsX3CalRuGKLg4rluC5CxaD23SOKzYp5mB0D1wtU2UQjZOpMHFz8YcBJ8/iYVHlv0lo s4Tx1mmBdyLBgd5YeO53d/N+pyf7VZkf7dHyl2uNuDNu5jeUpTbcVnAxhkf8xNO6BKZf64x0wnPwV +6pEQRVWBHCSJ4TorKzQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncyUu-001WLC-3E; Fri, 08 Apr 2022 23:58:36 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncyUr-001WKd-E8 for linux-arm-kernel@lists.infradead.org; Fri, 08 Apr 2022 23:58:34 +0000 Received: by mail-wm1-x333.google.com with SMTP id n35so6480411wms.5 for ; Fri, 08 Apr 2022 16:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=qd3xc3Ra5RdXly3fLoBNbPp+Yte3DEybTK7LULZsV3k=; b=UTGVqcy3UNBHn4SjP055yjMHx25cx36ejPBp1IwM+TK42xPMJWggb62u36PjAn6CNs erjoHyHU8VCNFk6fyYMl9z5v01Gp4wFgd/YNtvHzVZoUNO1l1su4dzjYvBw8kUi9XQGT Dqx4LfV7Q3W3Q2ELUZ+IriwQLR2xNOatUWwcD4gCTCxw1L69vExXISL5tvGEhODxE6Rx NyTL6VCNOxreRWn96Q5S2m2f20ESHMigOHCRieFZbYkKlad5VdovjvaPkuSuw/BSGDvW pPhBauUCmlFtTa8H2+PKUY86AjdMN4Ej5kEfWhaBYJ/9ht3pshbQ+wwXawCFIYrMD9Xn BSxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=qd3xc3Ra5RdXly3fLoBNbPp+Yte3DEybTK7LULZsV3k=; b=X5Kmqsn3MQ27TxRGKrslXiGlp0KAq5iUh7qxQsfGAJqzCo4D4LJJ/SgnRhIJmsDmJ/ zVDhOpIhLz70S10D44UnDbBhV0DYjlopf1yGS74wYoD4UyCjiGuMPB+nrAgh/DWc7ir3 3/YyZyVjhTGdK4cQnKmnEy6H/6v88LDwQ9hCSVjVowZOfRx6BP8c9Utr/jJyAeuxHf0I MxLJEbBUbonNRARspurYGHATuWirurqOHl/RqUTTIC6k1FRGDAY52Ike/bui6KWLL71L RJWTHttX2/3GkRWFBBIp2aP/Da5f1M5mWYcjyx+1B4fOxnL6RDqwD7+7uK7WbbBF1H0e GCVQ== X-Gm-Message-State: AOAM533FoZI5G4y5zWV+kXCox4/4TM96HhmAzm3cBagSjrazdNhfv6sy CSGeXE9R1KyY7/N3908+Pug= X-Google-Smtp-Source: ABdhPJwvJD+Cmd/2tHHonwkEVj4aZLwFznxjwZ531F0NRT9DZUNezEkyG1rHEVZvGmv1umZ1GStMeg== X-Received: by 2002:a7b:c844:0:b0:38e:7c92:a9e3 with SMTP id c4-20020a7bc844000000b0038e7c92a9e3mr18808150wml.140.1649462311057; Fri, 08 Apr 2022 16:58:31 -0700 (PDT) Received: from smtpclient.apple ([185.238.38.242]) by smtp.gmail.com with ESMTPSA id o17-20020a05600c4fd100b0038cd5074c83sm12043743wmq.34.2022.04.08.16.58.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2022 16:58:30 -0700 (PDT) Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.1.1\)) Subject: Re: [PATCH net-next 02/15] net: dsa: sja1105: Remove usage of iterator for list_add() after loop From: Jakob Koschel In-Reply-To: <20220407205426.6a31e4b2@kernel.org> Date: Sat, 9 Apr 2022 01:58:29 +0200 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." Message-Id: References: <20220407102900.3086255-1-jakobkoschel@gmail.com> <20220407102900.3086255-3-jakobkoschel@gmail.com> <20220407205426.6a31e4b2@kernel.org> To: Jakub Kicinski X-Mailer: Apple Mail (2.3696.80.82.1.1) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_165833_512357_BEC7039B X-CRM114-Status: GOOD ( 19.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hello Jakub, > On 8. Apr 2022, at 05:54, Jakub Kicinski wrote: > > 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". I'm not entirely sure I understand what you mean with "open coded the iteration". But maybe the solution proposed by Vladimir [1] works for you? I'm planning to rewrite the cases in that way for the relevant ones. > > Also the list_add() could be converted to list_add_tail(). Good point, I wasn't sure if that's considered as something that should be done as a separate change. I'm happy to include it in v2. Thanks for the input. Jakob [1] https://lore.kernel.org/linux-kernel/20220408114120.tvf2lxvhfqbnrlml@skbuf/ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel