netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: dsa: Initialize ds->cpu_port_mask earlier
@ 2017-07-24 17:49 Florian Fainelli
  2017-07-25  0:36 ` David Miller
  2017-07-26  2:13 ` Sean Wang
  0 siblings, 2 replies; 3+ messages in thread
From: Florian Fainelli @ 2017-07-24 17:49 UTC (permalink / raw)
  To: netdev; +Cc: sean.wang, andrew, vivien.didelot, davem, Florian Fainelli

The mt7530 driver has its dsa_switch_ops::get_tag_protocol function
check ds->cpu_port_mask to issue a warning in case the configured CPU
port is not capable of supporting tags.

After commit 14be36c2c96c ("net: dsa: Initialize all CPU and enabled
ports masks in dsa_ds_parse()") we slightly re-arranged the
initialization such that this was no longer working. Just make sure that
ds->cpu_port_mask is set prior to the first call to get_tag_protocol,
thus restoring the expected contract. In case of error, the CPU port bit
is cleared.

Fixes: 14be36c2c96c ("net: dsa: Initialize all CPU and enabled ports masks in dsa_ds_parse()")
Reported-by: Sean Wang <sean.wang@mediatek.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
Sean, can you check this does fix the problem you originally reported
correctly for you? Thanks!

 net/dsa/dsa2.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 56e46090526b..c442051d5a55 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -509,21 +509,22 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
 		dst->cpu_dp->netdev = ethernet_dev;
 	}
 
+	/* Initialize cpu_port_mask now for drv->setup()
+	 * to have access to a correct value, just like what
+	 * net/dsa/dsa.c::dsa_switch_setup_one does.
+	 */
+	ds->cpu_port_mask |= BIT(index);
+
 	tag_protocol = ds->ops->get_tag_protocol(ds);
 	dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol);
 	if (IS_ERR(dst->tag_ops)) {
 		dev_warn(ds->dev, "No tagger for this switch\n");
+		ds->cpu_port_mask &= ~BIT(index);
 		return PTR_ERR(dst->tag_ops);
 	}
 
 	dst->rcv = dst->tag_ops->rcv;
 
-	/* Initialize cpu_port_mask now for drv->setup()
-	 * to have access to a correct value, just like what
-	 * net/dsa/dsa.c::dsa_switch_setup_one does.
-	 */
-	ds->cpu_port_mask |= BIT(index);
-
 	return 0;
 }
 
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: dsa: Initialize ds->cpu_port_mask earlier
  2017-07-24 17:49 [PATCH net] net: dsa: Initialize ds->cpu_port_mask earlier Florian Fainelli
@ 2017-07-25  0:36 ` David Miller
  2017-07-26  2:13 ` Sean Wang
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-07-25  0:36 UTC (permalink / raw)
  To: f.fainelli; +Cc: netdev, sean.wang, andrew, vivien.didelot

From: Florian Fainelli <f.fainelli@gmail.com>
Date: Mon, 24 Jul 2017 10:49:23 -0700

> The mt7530 driver has its dsa_switch_ops::get_tag_protocol function
> check ds->cpu_port_mask to issue a warning in case the configured CPU
> port is not capable of supporting tags.
> 
> After commit 14be36c2c96c ("net: dsa: Initialize all CPU and enabled
> ports masks in dsa_ds_parse()") we slightly re-arranged the
> initialization such that this was no longer working. Just make sure that
> ds->cpu_port_mask is set prior to the first call to get_tag_protocol,
> thus restoring the expected contract. In case of error, the CPU port bit
> is cleared.
> 
> Fixes: 14be36c2c96c ("net: dsa: Initialize all CPU and enabled ports masks in dsa_ds_parse()")
> Reported-by: Sean Wang <sean.wang@mediatek.com>
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

Applied, thanks Florian.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: dsa: Initialize ds->cpu_port_mask earlier
  2017-07-24 17:49 [PATCH net] net: dsa: Initialize ds->cpu_port_mask earlier Florian Fainelli
  2017-07-25  0:36 ` David Miller
@ 2017-07-26  2:13 ` Sean Wang
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Wang @ 2017-07-26  2:13 UTC (permalink / raw)
  To: Florian Fainelli; +Cc: netdev, andrew, vivien.didelot, davem, linux-mediatek

Hi, Florian

the solution is better and also can fix the problem I originally
reported. Thank for your immediate help :-)

Sean


On Mon, 2017-07-24 at 10:49 -0700, Florian Fainelli wrote:
> The mt7530 driver has its dsa_switch_ops::get_tag_protocol function
> check ds->cpu_port_mask to issue a warning in case the configured CPU
> port is not capable of supporting tags.
> 
> After commit 14be36c2c96c ("net: dsa: Initialize all CPU and enabled
> ports masks in dsa_ds_parse()") we slightly re-arranged the
> initialization such that this was no longer working. Just make sure that
> ds->cpu_port_mask is set prior to the first call to get_tag_protocol,
> thus restoring the expected contract. In case of error, the CPU port bit
> is cleared.
> 
> Fixes: 14be36c2c96c ("net: dsa: Initialize all CPU and enabled ports masks in dsa_ds_parse()")
> Reported-by: Sean Wang <sean.wang@mediatek.com>
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
> Sean, can you check this does fix the problem you originally reported
> correctly for you? Thanks!
> 
>  net/dsa/dsa2.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
> index 56e46090526b..c442051d5a55 100644
> --- a/net/dsa/dsa2.c
> +++ b/net/dsa/dsa2.c
> @@ -509,21 +509,22 @@ static int dsa_cpu_parse(struct dsa_port *port, u32 index,
>  		dst->cpu_dp->netdev = ethernet_dev;
>  	}
>  
> +	/* Initialize cpu_port_mask now for drv->setup()
> +	 * to have access to a correct value, just like what
> +	 * net/dsa/dsa.c::dsa_switch_setup_one does.
> +	 */
> +	ds->cpu_port_mask |= BIT(index);
> +
>  	tag_protocol = ds->ops->get_tag_protocol(ds);
>  	dst->tag_ops = dsa_resolve_tag_protocol(tag_protocol);
>  	if (IS_ERR(dst->tag_ops)) {
>  		dev_warn(ds->dev, "No tagger for this switch\n");
> +		ds->cpu_port_mask &= ~BIT(index);
>  		return PTR_ERR(dst->tag_ops);
>  	}
>  
>  	dst->rcv = dst->tag_ops->rcv;
>  
> -	/* Initialize cpu_port_mask now for drv->setup()
> -	 * to have access to a correct value, just like what
> -	 * net/dsa/dsa.c::dsa_switch_setup_one does.
> -	 */
> -	ds->cpu_port_mask |= BIT(index);
> -
>  	return 0;
>  }
>  

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-07-26  2:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-24 17:49 [PATCH net] net: dsa: Initialize ds->cpu_port_mask earlier Florian Fainelli
2017-07-25  0:36 ` David Miller
2017-07-26  2:13 ` Sean Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).