[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220407205426.6a31e4b2@kernel.org>
Date: Thu, 7 Apr 2022 20:54:26 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: Jakob Koschel <jakobkoschel@...il.com>
Cc: "David S. Miller" <davem@...emloft.net>,
Paolo Abeni <pabeni@...hat.com>, Andrew Lunn <andrew@...n.ch>,
Vivien Didelot <vivien.didelot@...il.com>,
Florian Fainelli <f.fainelli@...il.com>,
Vladimir Oltean <olteanv@...il.com>,
Lars Povlsen <lars.povlsen@...rochip.com>,
Steen Hegelund <Steen.Hegelund@...rochip.com>,
UNGLinuxDriver@...rochip.com, Ariel Elior <aelior@...vell.com>,
Manish Chopra <manishc@...vell.com>,
Edward Cree <ecree.xilinx@...il.com>,
Martin Habets <habetsm.xilinx@...il.com>,
Michael Ellerman <mpe@...erman.id.au>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Paul Mackerras <paulus@...ba.org>,
Jiri Pirko <jiri@...nulli.us>,
Casper Andersson <casper.casan@...il.com>,
Bjarni Jonasson <bjarni.jonasson@...rochip.com>,
Colin Ian King <colin.king@...el.com>,
Michael Walle <michael@...le.cc>,
Christophe JAILLET <christophe.jaillet@...adoo.fr>,
Arnd Bergmann <arnd@...db.de>,
Eric Dumazet <edumazet@...gle.com>,
Di Zhu <zhudi21@...wei.com>, Xu Wang <vulab@...as.ac.cn>,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linuxppc-dev@...ts.ozlabs.org, Mike Rapoport <rppt@...nel.org>,
"Brian Johannesmeyer" <bjohannesmeyer@...il.com>,
Cristiano Giuffrida <c.giuffrida@...nl>,
"Bos, H.J." <h.j.bos@...nl>
Subject: Re: [PATCH net-next 02/15] net: dsa: sja1105: Remove usage of
iterator for list_add() after loop
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().
Powered by blists - more mailing lists