diff mbox series

[net-next,09/13] net: dsa: lantiq_gswip: Forbid gswip_add_single_port_br on the CPU port

Message ID 20240606085234.565551-10-ms@dev.tdt.de (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: dsa: lantiq_gswip: code improvements | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 901 this patch: 901
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 905 this patch: 905
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 905 this patch: 905
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-06-07--09-00 (tests: 1041)

Commit Message

Martin Schiller June 6, 2024, 8:52 a.m. UTC
From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>

Calling gswip_add_single_port_br() with the CPU port would be a bug
because then only the CPU port could talk to itself. Add the CPU port to
the validation at the beginning of gswip_add_single_port_br().

Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
---
 drivers/net/dsa/lantiq_gswip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Vladimir Oltean June 7, 2024, 11:26 a.m. UTC | #1
On Thu, Jun 06, 2024 at 10:52:30AM +0200, Martin Schiller wrote:
> From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> 
> Calling gswip_add_single_port_br() with the CPU port would be a bug
> because then only the CPU port could talk to itself. Add the CPU port to
> the validation at the beginning of gswip_add_single_port_br().
> 
> Signed-off-by: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> ---
>  drivers/net/dsa/lantiq_gswip.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
> index ee8296d5b901..d2195271ffe9 100644
> --- a/drivers/net/dsa/lantiq_gswip.c
> +++ b/drivers/net/dsa/lantiq_gswip.c
> @@ -657,7 +657,7 @@ static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add)
>  	unsigned int max_ports = priv->hw_info->max_ports;
>  	int err;
>  
> -	if (port >= max_ports) {
> +	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
>  		dev_err(priv->dev, "single port for %i supported\n", port);
>  		return -EIO;
>  	}
> -- 
> 2.39.2
> 

Isn't the new check effectively dead code?
Martin Schiller June 7, 2024, 1:31 p.m. UTC | #2
On 2024-06-07 13:26, Vladimir Oltean wrote:
> On Thu, Jun 06, 2024 at 10:52:30AM +0200, Martin Schiller wrote:
>> From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
>> 
>> Calling gswip_add_single_port_br() with the CPU port would be a bug
>> because then only the CPU port could talk to itself. Add the CPU port 
>> to
>> the validation at the beginning of gswip_add_single_port_br().
>> 
>> Signed-off-by: Martin Blumenstingl 
>> <martin.blumenstingl@googlemail.com>
>> ---
>>  drivers/net/dsa/lantiq_gswip.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/net/dsa/lantiq_gswip.c 
>> b/drivers/net/dsa/lantiq_gswip.c
>> index ee8296d5b901..d2195271ffe9 100644
>> --- a/drivers/net/dsa/lantiq_gswip.c
>> +++ b/drivers/net/dsa/lantiq_gswip.c
>> @@ -657,7 +657,7 @@ static int gswip_add_single_port_br(struct 
>> gswip_priv *priv, int port, bool add)
>>  	unsigned int max_ports = priv->hw_info->max_ports;
>>  	int err;
>> 
>> -	if (port >= max_ports) {
>> +	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
>>  		dev_err(priv->dev, "single port for %i supported\n", port);
>>  		return -EIO;
>>  	}
>> --
>> 2.39.2
>> 
> 
> Isn't the new check effectively dead code?

As long as the dsa_switch_ops .port_bridge_join and .port_bridge_leave 
are not
executed for the cpu port, I agree with you.
Vladimir Oltean June 7, 2024, 1:49 p.m. UTC | #3
On Fri, Jun 07, 2024 at 03:31:57PM +0200, Martin Schiller wrote:
> On 2024-06-07 13:26, Vladimir Oltean wrote:
> > On Thu, Jun 06, 2024 at 10:52:30AM +0200, Martin Schiller wrote:
> > > From: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
> > > 
> > > Calling gswip_add_single_port_br() with the CPU port would be a bug
> > > because then only the CPU port could talk to itself. Add the CPU
> > > port to
> > > the validation at the beginning of gswip_add_single_port_br().
> > > 
> > > Signed-off-by: Martin Blumenstingl
> > > <martin.blumenstingl@googlemail.com>
> > > ---
> > >  drivers/net/dsa/lantiq_gswip.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/net/dsa/lantiq_gswip.c
> > > b/drivers/net/dsa/lantiq_gswip.c
> > > index ee8296d5b901..d2195271ffe9 100644
> > > --- a/drivers/net/dsa/lantiq_gswip.c
> > > +++ b/drivers/net/dsa/lantiq_gswip.c
> > > @@ -657,7 +657,7 @@ static int gswip_add_single_port_br(struct
> > > gswip_priv *priv, int port, bool add)
> > >  	unsigned int max_ports = priv->hw_info->max_ports;
> > >  	int err;
> > > 
> > > -	if (port >= max_ports) {
> > > +	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
> > >  		dev_err(priv->dev, "single port for %i supported\n", port);
> > >  		return -EIO;
> > >  	}
> > > --
> > > 2.39.2
> > > 
> > 
> > Isn't the new check effectively dead code?
> 
> As long as the dsa_switch_ops .port_bridge_join and .port_bridge_leave are not
> executed for the cpu port, I agree with you.

They aren't. The primary trigger for dsa_port_bridge_join() is dsa_user_changeupper(),
along with other code paths that replay the operation in certain circumstances,
again only for user ports.
diff mbox series

Patch

diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index ee8296d5b901..d2195271ffe9 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -657,7 +657,7 @@  static int gswip_add_single_port_br(struct gswip_priv *priv, int port, bool add)
 	unsigned int max_ports = priv->hw_info->max_ports;
 	int err;
 
-	if (port >= max_ports) {
+	if (port >= max_ports || dsa_is_cpu_port(priv->ds, port)) {
 		dev_err(priv->dev, "single port for %i supported\n", port);
 		return -EIO;
 	}