OSDN Git Service

net: dsa: add dsa_is_unused_port helper
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>
Thu, 26 Oct 2017 15:22:51 +0000 (11:22 -0400)
committerDavid S. Miller <davem@davemloft.net>
Fri, 27 Oct 2017 15:00:09 +0000 (00:00 +0900)
As the comment above the chunk states, the b53 driver attempts to
disable the unused ports. But using ds->enabled_port_mask is misleading,
because this mask reports in fact the user ports.

To avoid confusion and fix this, this patch introduces an explicit
dsa_is_unused_port helper which ensures the corresponding bit is not
masked in any of the switch port masks.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/b53/b53_common.c
include/net/dsa.h

index b48cf04..c74a501 100644 (file)
@@ -873,7 +873,7 @@ static int b53_setup(struct dsa_switch *ds)
        for (port = 0; port < dev->num_ports; port++) {
                if (dsa_is_cpu_port(ds, port))
                        b53_enable_cpu_port(dev, port);
-               else if (!(BIT(port) & ds->enabled_port_mask))
+               else if (dsa_is_unused_port(ds, port))
                        b53_disable_port(ds, port, NULL);
        }
 
index 38961ef..6b1bc1c 100644 (file)
@@ -254,6 +254,13 @@ struct dsa_switch {
        struct dsa_port ports[];
 };
 
+static inline bool dsa_is_unused_port(struct dsa_switch *ds, int p)
+{
+       u32 m = ds->enabled_port_mask | ds->dsa_port_mask | ds->cpu_port_mask;
+
+       return !(m & BIT(p));
+}
+
 static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
 {
        return !!(ds->cpu_port_mask & (1 << p));