2019-10-20 03:20:48

by Vivien Didelot

[permalink] [raw]
Subject: [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port

Use the new ports list instead of accessing the dsa_switch array
of ports in the dsa_to_port helper.

Signed-off-by: Vivien Didelot <[email protected]>
---
include/net/dsa.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 6ff6dfcdc61d..938de9518c61 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -285,7 +285,14 @@ struct dsa_switch {

static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
{
- return &ds->ports[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_unused_port(struct dsa_switch *ds, int p)
--
2.23.0


2019-10-21 02:39:21

by Florian Fainelli

[permalink] [raw]
Subject: Re: [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port



On 10/19/2019 8:19 PM, Vivien Didelot wrote:
> Use the new ports list instead of accessing the dsa_switch array
> of ports in the dsa_to_port helper.
>
> Signed-off-by: Vivien Didelot <[email protected]>
> ---
> include/net/dsa.h | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/include/net/dsa.h b/include/net/dsa.h
> index 6ff6dfcdc61d..938de9518c61 100644
> --- a/include/net/dsa.h
> +++ b/include/net/dsa.h
> @@ -285,7 +285,14 @@ struct dsa_switch {
>
> static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p)
> {
> - return &ds->ports[p];
> + struct dsa_switch_tree *dst = ds->dst;
> + struct dsa_port *dp;

I would initialize this to NULL and always return dp

> +
> + list_for_each_entry(dp, &dst->ports, list)
> + if (dp->ds == ds && dp->index == p)
> + return dp;

and do a break here, but this is strictly identical to your code, so it
boils down to a matter of preference.

Do you possibly need to use list_for_ech_entry_safe() here, especially
for the code paths that deal with the unregistering of a switch/switch
fabric? That also raises the question of locking as well, which can be
punted on the caller if that is appropriate.

Other than that:

Reviewed-by: Florian Fainelli <[email protected]>
--
Florian

2019-10-21 12:40:20

by Andrew Lunn

[permalink] [raw]
Subject: Re: [PATCH net-next 03/16] net: dsa: use ports list in dsa_to_port

On Sat, Oct 19, 2019 at 11:19:28PM -0400, Vivien Didelot wrote:
> Use the new ports list instead of accessing the dsa_switch array
> of ports in the dsa_to_port helper.
>
> Signed-off-by: Vivien Didelot <[email protected]>

Reviewed-by: Andrew Lunn <[email protected]>

Andrew