OSDN Git Service

net: dsa: get port name at parse time
authorVivien Didelot <vivien.didelot@savoirfairelinux.com>
Fri, 27 Oct 2017 19:55:18 +0000 (15:55 -0400)
committerDavid S. Miller <davem@davemloft.net>
Wed, 1 Nov 2017 02:47:36 +0000 (11:47 +0900)
Get the optional "label" property and assign a default one directly at
parse time instead of doing it when creating the slave.

For legacy, simply assign the port name stored in cd->port_names.

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>
net/dsa/dsa2.c
net/dsa/legacy.c

index 8cd84c1..3c134ff 100644 (file)
@@ -260,11 +260,6 @@ static int dsa_user_port_apply(struct dsa_port *port)
        const char *name = port->name;
        int err;
 
-       if (port->dn)
-               name = of_get_property(port->dn, "label", NULL);
-       if (!name)
-               name = "eth%d";
-
        err = dsa_slave_create(port, name);
        if (err) {
                dev_warn(ds->dev, "Failed to create slave %d: %d\n",
@@ -564,6 +559,7 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
 {
        struct device_node *ethernet = of_parse_phandle(dn, "ethernet", 0);
        struct device_node *link = of_parse_phandle(dn, "link", 0);
+       const char *name = of_get_property(dn, "label", NULL);
 
        if (ethernet) {
                struct net_device *master;
@@ -577,7 +573,11 @@ static int dsa_port_parse_of(struct dsa_port *dp, struct device_node *dn)
        } else if (link) {
                dp->type = DSA_PORT_TYPE_DSA;
        } else {
+               if (!name)
+                       name = "eth%d";
+
                dp->type = DSA_PORT_TYPE_USER;
+               dp->name = name;
        }
 
        dp->dn = dn;
index ed7aae3..afe6e15 100644 (file)
@@ -115,6 +115,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,
                name = cd->port_names[i];
                if (name == NULL)
                        continue;
+               dp->name = name;
 
                if (!strcmp(name, "cpu")) {
                        if (dst->cpu_dp) {