[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211013101341.56223-1-dqfext@gmail.com>
Date: Wed, 13 Oct 2021 18:13:41 +0800
From: DENG Qingfang <dqfext@...il.com>
To: Alvin Šipraga <ALSI@...g-olufsen.dk>
Cc: Alvin Šipraga <alvin@...s.dk>,
Linus Walleij <linus.walleij@...aro.org>,
Andrew Lunn <andrew@...n.ch>,
Vivien Didelot <vivien.didelot@...il.com>,
Florian Fainelli <f.fainelli@...il.com>,
Vladimir Oltean <olteanv@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Heiner Kallweit <hkallweit1@...il.com>,
Russell King <linux@...linux.org.uk>,
Michael Rasmussen <MIR@...g-olufsen.dk>,
"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH net-next 5/6] net: dsa: realtek-smi: add rtl8365mb subdriver for RTL8365MB-VC
On Wed, Oct 13, 2021 at 10:05:21AM +0000, Alvin Šipraga wrote:
> Andrew also suggested this, but the discontinuity in port IDs seems to
> be an invitation for trouble. Here is an example of a series of
> functions from dsa.h:
>
> static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
> {
> struct dsa_switch_tree *dst = ds->dst;
> struct dsa_port *dp;
>
> list_for_each_entry(dp, &dst->ports, list)
> if (dp->ds == ds && dp->index == p)
> return dp;
>
> return NULL;
> }
>
> static inline bool dsa_is_user_port(struct dsa_switch *ds, int p)
> {
> return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER;
> }
>
> static inline u32 dsa_user_ports(struct dsa_switch *ds)
> {
> u32 mask = 0;
> int p;
>
> for (p = 0; p < ds->num_ports; p++)
> if (dsa_is_user_port(ds, p))
> mask |= BIT(p);
>
> return mask;
> }
>
> My reading of dsa_user_ports() is that the port IDs run from 0 to
> (ds->num_ports - 1). If num_ports is 5 (4 user ports and 1 CPU port, as
> in my case), but the CPU is port 6, will we not dereference NULL when
> calling dsa_is_user_port(ds, 4)?
So set num_ports to 7.
>
> >
> >> +
> >> +/* Chip-specific data and limits */
>
Powered by blists - more mailing lists