net: dsa: use ds->num_ports when possible
The dsa_switch structure contains the number of ports. Use it where the structure is valid instead of the DSA_MAX_PORTS value. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
a0c02161ec
commit
26895e299c
|
@ -145,7 +145,7 @@ static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev)
|
||||||
struct dsa_port *dport;
|
struct dsa_port *dport;
|
||||||
int ret, port;
|
int ret, port;
|
||||||
|
|
||||||
for (port = 0; port < DSA_MAX_PORTS; port++) {
|
for (port = 0; port < ds->num_ports; port++) {
|
||||||
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
|
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
|
||||||
/*
|
/*
|
||||||
* Validate supplied switch configuration.
|
* Validate supplied switch configuration.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < DSA_MAX_PORTS; i++) {
|
for (i = 0; i < ds->num_ports; i++) {
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
name = cd->port_names[i];
|
name = cd->port_names[i];
|
||||||
|
@ -242,7 +242,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
|
||||||
valid_name_found = true;
|
valid_name_found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid_name_found && i == DSA_MAX_PORTS)
|
if (!valid_name_found && i == ds->num_ports)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/* Make the built-in MII bus mask match the number of ports,
|
/* Make the built-in MII bus mask match the number of ports,
|
||||||
|
@ -295,7 +295,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
|
||||||
/*
|
/*
|
||||||
* Create network devices for physical switch ports.
|
* Create network devices for physical switch ports.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < DSA_MAX_PORTS; i++) {
|
for (i = 0; i < ds->num_ports; i++) {
|
||||||
ds->ports[i].dn = cd->port_dn[i];
|
ds->ports[i].dn = cd->port_dn[i];
|
||||||
|
|
||||||
if (!(ds->enabled_port_mask & (1 << i)))
|
if (!(ds->enabled_port_mask & (1 << i)))
|
||||||
|
@ -377,7 +377,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
|
||||||
int port;
|
int port;
|
||||||
|
|
||||||
/* Destroy network devices for physical switch ports. */
|
/* Destroy network devices for physical switch ports. */
|
||||||
for (port = 0; port < DSA_MAX_PORTS; port++) {
|
for (port = 0; port < ds->num_ports; port++) {
|
||||||
if (!(ds->enabled_port_mask & (1 << port)))
|
if (!(ds->enabled_port_mask & (1 << port)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disable configuration of the CPU and DSA ports */
|
/* Disable configuration of the CPU and DSA ports */
|
||||||
for (port = 0; port < DSA_MAX_PORTS; port++) {
|
for (port = 0; port < ds->num_ports; port++) {
|
||||||
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
|
if (!(dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)))
|
||||||
continue;
|
continue;
|
||||||
dsa_cpu_dsa_destroy(&ds->ports[port]);
|
dsa_cpu_dsa_destroy(&ds->ports[port]);
|
||||||
|
@ -408,7 +408,7 @@ int dsa_switch_suspend(struct dsa_switch *ds)
|
||||||
int i, ret = 0;
|
int i, ret = 0;
|
||||||
|
|
||||||
/* Suspend slave network devices */
|
/* Suspend slave network devices */
|
||||||
for (i = 0; i < DSA_MAX_PORTS; i++) {
|
for (i = 0; i < ds->num_ports; i++) {
|
||||||
if (!dsa_is_port_initialized(ds, i))
|
if (!dsa_is_port_initialized(ds, i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -435,7 +435,7 @@ int dsa_switch_resume(struct dsa_switch *ds)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Resume slave network devices */
|
/* Resume slave network devices */
|
||||||
for (i = 0; i < DSA_MAX_PORTS; i++) {
|
for (i = 0; i < ds->num_ports; i++) {
|
||||||
if (!dsa_is_port_initialized(ds, i))
|
if (!dsa_is_port_initialized(ds, i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ static bool dsa_ds_find_port_dn(struct dsa_switch *ds,
|
||||||
{
|
{
|
||||||
u32 index;
|
u32 index;
|
||||||
|
|
||||||
for (index = 0; index < DSA_MAX_PORTS; index++)
|
for (index = 0; index < ds->num_ports; index++)
|
||||||
if (ds->ports[index].dn == port)
|
if (ds->ports[index].dn == port)
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
|
@ -159,7 +159,7 @@ static int dsa_ds_complete(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
||||||
u32 index;
|
u32 index;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
for (index = 0; index < DSA_MAX_PORTS; index++) {
|
for (index = 0; index < ds->num_ports; index++) {
|
||||||
port = &ds->ports[index];
|
port = &ds->ports[index];
|
||||||
if (!dsa_port_is_valid(port))
|
if (!dsa_port_is_valid(port))
|
||||||
continue;
|
continue;
|
||||||
|
@ -312,7 +312,7 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index = 0; index < DSA_MAX_PORTS; index++) {
|
for (index = 0; index < ds->num_ports; index++) {
|
||||||
port = &ds->ports[index];
|
port = &ds->ports[index];
|
||||||
if (!dsa_port_is_valid(port))
|
if (!dsa_port_is_valid(port))
|
||||||
continue;
|
continue;
|
||||||
|
@ -344,7 +344,7 @@ static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
||||||
struct dsa_port *port;
|
struct dsa_port *port;
|
||||||
u32 index;
|
u32 index;
|
||||||
|
|
||||||
for (index = 0; index < DSA_MAX_PORTS; index++) {
|
for (index = 0; index < ds->num_ports; index++) {
|
||||||
port = &ds->ports[index];
|
port = &ds->ports[index];
|
||||||
if (!dsa_port_is_valid(port))
|
if (!dsa_port_is_valid(port))
|
||||||
continue;
|
continue;
|
||||||
|
@ -475,7 +475,7 @@ static int dsa_ds_parse(struct dsa_switch_tree *dst, struct dsa_switch *ds)
|
||||||
u32 index;
|
u32 index;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
for (index = 0; index < DSA_MAX_PORTS; index++) {
|
for (index = 0; index < ds->num_ports; index++) {
|
||||||
port = &ds->ports[index];
|
port = &ds->ports[index];
|
||||||
if (!dsa_port_is_valid(port))
|
if (!dsa_port_is_valid(port))
|
||||||
continue;
|
continue;
|
||||||
|
@ -529,7 +529,7 @@ static int dsa_parse_ports_dn(struct device_node *ports, struct dsa_switch *ds)
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (reg >= DSA_MAX_PORTS)
|
if (reg >= ds->num_ports)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ds->ports[reg].dn = port;
|
ds->ports[reg].dn = port;
|
||||||
|
|
|
@ -404,7 +404,7 @@ static int dsa_fastest_ageing_time(struct dsa_switch *ds,
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < DSA_MAX_PORTS; ++i) {
|
for (i = 0; i < ds->num_ports; ++i) {
|
||||||
struct dsa_port *dp = &ds->ports[i];
|
struct dsa_port *dp = &ds->ports[i];
|
||||||
|
|
||||||
if (dp && dp->ageing_time && dp->ageing_time < ageing_time)
|
if (dp && dp->ageing_time && dp->ageing_time < ageing_time)
|
||||||
|
|
|
@ -128,7 +128,7 @@ static int brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev,
|
||||||
source_port = brcm_tag[3] & BRCM_EG_PID_MASK;
|
source_port = brcm_tag[3] & BRCM_EG_PID_MASK;
|
||||||
|
|
||||||
/* Validate port against switch setup, either the port is totally */
|
/* Validate port against switch setup, either the port is totally */
|
||||||
if (source_port >= DSA_MAX_PORTS || !ds->ports[source_port].netdev)
|
if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
|
||||||
goto out_drop;
|
goto out_drop;
|
||||||
|
|
||||||
/* Remove Broadcom tag and update checksum */
|
/* Remove Broadcom tag and update checksum */
|
||||||
|
|
|
@ -114,7 +114,7 @@ static int dsa_rcv(struct sk_buff *skb, struct net_device *dev,
|
||||||
if (!ds)
|
if (!ds)
|
||||||
goto out_drop;
|
goto out_drop;
|
||||||
|
|
||||||
if (source_port >= DSA_MAX_PORTS || !ds->ports[source_port].netdev)
|
if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
|
||||||
goto out_drop;
|
goto out_drop;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -127,7 +127,7 @@ static int edsa_rcv(struct sk_buff *skb, struct net_device *dev,
|
||||||
if (!ds)
|
if (!ds)
|
||||||
goto out_drop;
|
goto out_drop;
|
||||||
|
|
||||||
if (source_port >= DSA_MAX_PORTS || !ds->ports[source_port].netdev)
|
if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
|
||||||
goto out_drop;
|
goto out_drop;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -82,7 +82,7 @@ static int trailer_rcv(struct sk_buff *skb, struct net_device *dev,
|
||||||
goto out_drop;
|
goto out_drop;
|
||||||
|
|
||||||
source_port = trailer[1] & 7;
|
source_port = trailer[1] & 7;
|
||||||
if (source_port >= DSA_MAX_PORTS || !ds->ports[source_port].netdev)
|
if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
|
||||||
goto out_drop;
|
goto out_drop;
|
||||||
|
|
||||||
pskb_trim_rcsum(skb, skb->len - 4);
|
pskb_trim_rcsum(skb, skb->len - 4);
|
||||||
|
|
Loading…
Reference in New Issue