netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: dsa: mv88e6xxx: Fix opps when adding vlan bridge
@ 2016-12-11 20:07 Andrew Lunn
  2016-12-11 21:02 ` Vivien Didelot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Andrew Lunn @ 2016-12-11 20:07 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Vivien Didelot, Andrew Lunn

A port is not necessarily assigned to a netdev. And a port does not
need to be a member of a bridge. So when iterating over all ports,
check before using the netdev and bridge_dev for a port. Otherwise we
dereference a NULL pointer.

Fixes: da9c359e19f0 ("net: dsa: mv88e6xxx: check hardware VLAN in use")
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/dsa/mv88e6xxx/chip.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 883fd9809dd2..4e5ab856b87a 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -1796,6 +1796,9 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
 			if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
 				continue;
 
+			if (!ds->ports[port].netdev)
+				continue;
+
 			if (vlan.data[i] ==
 			    GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
 				continue;
@@ -1804,6 +1807,9 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
 			    chip->ports[port].bridge_dev)
 				break; /* same bridge, check next VLAN */
 
+			if (!chip->ports[i].bridge_dev)
+				continue;
+
 			netdev_warn(ds->ports[port].netdev,
 				    "hardware VLAN %d already used by %s\n",
 				    vlan.vid,
-- 
2.10.2

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

* Re: [PATCH net] net: dsa: mv88e6xxx: Fix opps when adding vlan bridge
  2016-12-11 20:07 [PATCH net] net: dsa: mv88e6xxx: Fix opps when adding vlan bridge Andrew Lunn
@ 2016-12-11 21:02 ` Vivien Didelot
  2016-12-12 13:04   ` Andrew Lunn
  2016-12-12 13:15 ` Vivien Didelot
  2016-12-16 18:27 ` David Miller
  2 siblings, 1 reply; 5+ messages in thread
From: Vivien Didelot @ 2016-12-11 21:02 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Andrew Lunn

Hi Andrew,

Andrew Lunn <andrew@lunn.ch> writes:

> @@ -1804,6 +1807,9 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
>  			    chip->ports[port].bridge_dev)
>  				break; /* same bridge, check next VLAN */
>  
> +			if (!chip->ports[i].bridge_dev)
> +				continue;
> +

The above truncated test:

			if (chip->ports[i].bridge_dev ==
			    chip->ports[port].bridge_dev)
				break; /* same bridge, check next VLAN */

should handle the case where bridge_dev is NULL, but if you want to
explicitly test it, I'd move it before this statement.

>  			netdev_warn(ds->ports[port].netdev,
>  				    "hardware VLAN %d already used by %s\n",
>  				    vlan.vid,


Thanks,

        Vivien

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

* Re: [PATCH net] net: dsa: mv88e6xxx: Fix opps when adding vlan bridge
  2016-12-11 21:02 ` Vivien Didelot
@ 2016-12-12 13:04   ` Andrew Lunn
  0 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2016-12-12 13:04 UTC (permalink / raw)
  To: Vivien Didelot; +Cc: David Miller, netdev

On Sun, Dec 11, 2016 at 04:02:37PM -0500, Vivien Didelot wrote:
> Hi Andrew,
> 
> Andrew Lunn <andrew@lunn.ch> writes:
> 
> > @@ -1804,6 +1807,9 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port,
> >  			    chip->ports[port].bridge_dev)
> >  				break; /* same bridge, check next VLAN */
> >  
> > +			if (!chip->ports[i].bridge_dev)
> > +				continue;
> > +
> 
> The above truncated test:
> 
> 			if (chip->ports[i].bridge_dev ==
> 			    chip->ports[port].bridge_dev)
> 				break; /* same bridge, check next VLAN */
> 
> should handle the case where bridge_dev is NULL, but if you want to
> explicitly test it, I'd move it before this statement.
> 
> >  			netdev_warn(ds->ports[port].netdev,
> >  				    "hardware VLAN %d already used by %s\n",
> >  				    vlan.vid,

Hi Vivien

I don't think you comment is correct. Here is the loop, with my two
additions.

                for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
                        if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i))
                                continue;

                        if (!ds->ports[port].netdev)
                                continue;

                        if (vlan.data[i] ==
                            GLOBAL_VTU_DATA_MEMBER_TAG_NON_MEMBER)
                                continue;

                        if (chip->ports[i].bridge_dev ==
                            chip->ports[port].bridge_dev)
                                break; /* same bridge, check next VLAN */

                        if (!chip->ports[i].bridge_dev)
                                continue;

                        netdev_warn(ds->ports[port].netdev,
                                    "hardware VLAN %d already used by %s\n",
                                    vlan.vid,
                                    netdev_name(chip->ports[i].bridge_dev));
                        err = -EOPNOTSUPP;
                        goto unlock;
                }

The opps was occurring in netdev_name(). I did not check which
one. The obvious one, or the netdev_warn(netdev,... one.

> The above truncated test:
> 
> 			if (chip->ports[i].bridge_dev ==
> 			    chip->ports[port].bridge_dev)
> 				break; /* same bridge, check next VLAN */
>
> should handle the case where bridge_dev is NULL, but if you want to
> explicitly test it, I'd move it before this statement.

This will not stop chip->ports[i].bridge_dev == NULL from reaching the
netdev_warn().

	Andrew

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

* Re: [PATCH net] net: dsa: mv88e6xxx: Fix opps when adding vlan bridge
  2016-12-11 20:07 [PATCH net] net: dsa: mv88e6xxx: Fix opps when adding vlan bridge Andrew Lunn
  2016-12-11 21:02 ` Vivien Didelot
@ 2016-12-12 13:15 ` Vivien Didelot
  2016-12-16 18:27 ` David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: Vivien Didelot @ 2016-12-12 13:15 UTC (permalink / raw)
  To: Andrew Lunn, David Miller; +Cc: netdev, Andrew Lunn

Hi Andrew,

Andrew Lunn <andrew@lunn.ch> writes:

> A port is not necessarily assigned to a netdev. And a port does not
> need to be a member of a bridge. So when iterating over all ports,
> check before using the netdev and bridge_dev for a port. Otherwise we
> dereference a NULL pointer.
>
> Fixes: da9c359e19f0 ("net: dsa: mv88e6xxx: check hardware VLAN in use")
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>

Thanks,

        Vivien

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

* Re: [PATCH net] net: dsa: mv88e6xxx: Fix opps when adding vlan bridge
  2016-12-11 20:07 [PATCH net] net: dsa: mv88e6xxx: Fix opps when adding vlan bridge Andrew Lunn
  2016-12-11 21:02 ` Vivien Didelot
  2016-12-12 13:15 ` Vivien Didelot
@ 2016-12-16 18:27 ` David Miller
  2 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2016-12-16 18:27 UTC (permalink / raw)
  To: andrew; +Cc: netdev, vivien.didelot

From: Andrew Lunn <andrew@lunn.ch>
Date: Sun, 11 Dec 2016 21:07:19 +0100

> A port is not necessarily assigned to a netdev. And a port does not
> need to be a member of a bridge. So when iterating over all ports,
> check before using the netdev and bridge_dev for a port. Otherwise we
> dereference a NULL pointer.
> 
> Fixes: da9c359e19f0 ("net: dsa: mv88e6xxx: check hardware VLAN in use")
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>

Applied.

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

end of thread, other threads:[~2016-12-16 18:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-11 20:07 [PATCH net] net: dsa: mv88e6xxx: Fix opps when adding vlan bridge Andrew Lunn
2016-12-11 21:02 ` Vivien Didelot
2016-12-12 13:04   ` Andrew Lunn
2016-12-12 13:15 ` Vivien Didelot
2016-12-16 18:27 ` David Miller

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).