netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: dsa: Fix legacy probing
@ 2017-06-16 23:42 Florian Fainelli
  2017-06-17 17:52 ` Vivien Didelot
  2017-06-18  3:00 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Florian Fainelli @ 2017-06-16 23:42 UTC (permalink / raw)
  To: netdev; +Cc: davem, andrew, vivien.didelot, jcobham, Florian Fainelli

After commit 6d3c8c0dd88a ("net: dsa: Remove master_netdev and
use dst->cpu_dp->netdev") and a29342e73911 ("net: dsa: Associate
slave network device with CPU port") we would be seeing NULL pointer
dereferences when accessing dst->cpu_dp->netdev too early. In the legacy
code, we actually know early in advance the master network device, so
pass it down to the relevant functions.

Fixes: 6d3c8c0dd88a ("net: dsa: Remove master_netdev and use dst->cpu_dp->netdev")
Fixes: a29342e73911 ("net: dsa: Associate slave network device with CPU port")
Reported-by: Jason Cobham <jcobham@questertangent.com>
Tested-by: Jason Cobham <jcobham@questertangent.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 net/dsa/legacy.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/net/dsa/legacy.c b/net/dsa/legacy.c
index e60906125375..1d7a3282f2a7 100644
--- a/net/dsa/legacy.c
+++ b/net/dsa/legacy.c
@@ -95,18 +95,16 @@ static int dsa_cpu_dsa_setups(struct dsa_switch *ds, struct device *dev)
 	return 0;
 }
 
-static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
+static int dsa_switch_setup_one(struct dsa_switch *ds, struct net_device *master,
+				struct device *parent)
 {
 	const struct dsa_switch_ops *ops = ds->ops;
 	struct dsa_switch_tree *dst = ds->dst;
 	struct dsa_chip_data *cd = ds->cd;
 	bool valid_name_found = false;
-	struct net_device *master;
 	int index = ds->index;
 	int i, ret;
 
-	master = dst->cpu_dp->netdev;
-
 	/*
 	 * Validate supplied switch configuration.
 	 */
@@ -124,12 +122,12 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
 				return -EINVAL;
 			}
 			dst->cpu_dp = &ds->ports[i];
+			dst->cpu_dp->netdev = master;
 			ds->cpu_port_mask |= 1 << i;
 		} else if (!strcmp(name, "dsa")) {
 			ds->dsa_port_mask |= 1 << i;
 		} else {
 			ds->enabled_port_mask |= 1 << i;
-			ds->ports[i].cpu_dp = dst->cpu_dp;
 		}
 		valid_name_found = true;
 	}
@@ -193,6 +191,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
 	 */
 	for (i = 0; i < ds->num_ports; i++) {
 		ds->ports[i].dn = cd->port_dn[i];
+		ds->ports[i].cpu_dp = dst->cpu_dp;
 
 		if (!(ds->enabled_port_mask & (1 << i)))
 			continue;
@@ -217,11 +216,10 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, struct device *parent)
 }
 
 static struct dsa_switch *
-dsa_switch_setup(struct dsa_switch_tree *dst, int index,
-		 struct device *parent, struct device *host_dev)
+dsa_switch_setup(struct dsa_switch_tree *dst, struct net_device *master,
+		 int index, struct device *parent, struct device *host_dev)
 {
 	struct dsa_chip_data *cd = dst->pd->chip + index;
-	struct net_device *master = dst->cpu_dp->netdev;
 	const struct dsa_switch_ops *ops;
 	struct dsa_switch *ds;
 	int ret;
@@ -254,7 +252,7 @@ dsa_switch_setup(struct dsa_switch_tree *dst, int index,
 	ds->ops = ops;
 	ds->priv = priv;
 
-	ret = dsa_switch_setup_one(ds, parent);
+	ret = dsa_switch_setup_one(ds, master, parent);
 	if (ret)
 		return ERR_PTR(ret);
 
@@ -580,12 +578,11 @@ static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
 	unsigned configured = 0;
 
 	dst->pd = pd;
-	dst->cpu_dp->netdev = dev;
 
 	for (i = 0; i < pd->nr_chips; i++) {
 		struct dsa_switch *ds;
 
-		ds = dsa_switch_setup(dst, i, parent, pd->chip[i].host_dev);
+		ds = dsa_switch_setup(dst, dev, i, parent, pd->chip[i].host_dev);
 		if (IS_ERR(ds)) {
 			netdev_err(dev, "[%d]: couldn't create dsa switch instance (error %ld)\n",
 				   i, PTR_ERR(ds));
-- 
2.9.3

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

* Re: [PATCH net-next] net: dsa: Fix legacy probing
  2017-06-16 23:42 [PATCH net-next] net: dsa: Fix legacy probing Florian Fainelli
@ 2017-06-17 17:52 ` Vivien Didelot
  2017-06-18  3:00 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Vivien Didelot @ 2017-06-17 17:52 UTC (permalink / raw)
  To: Florian Fainelli, netdev; +Cc: davem, andrew, jcobham, Florian Fainelli

Florian Fainelli <f.fainelli@gmail.com> writes:

> After commit 6d3c8c0dd88a ("net: dsa: Remove master_netdev and
> use dst->cpu_dp->netdev") and a29342e73911 ("net: dsa: Associate
> slave network device with CPU port") we would be seeing NULL pointer
> dereferences when accessing dst->cpu_dp->netdev too early. In the legacy
> code, we actually know early in advance the master network device, so
> pass it down to the relevant functions.
>
> Fixes: 6d3c8c0dd88a ("net: dsa: Remove master_netdev and use dst->cpu_dp->netdev")
> Fixes: a29342e73911 ("net: dsa: Associate slave network device with CPU port")
> Reported-by: Jason Cobham <jcobham@questertangent.com>
> Tested-by: Jason Cobham <jcobham@questertangent.com>
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

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

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

* Re: [PATCH net-next] net: dsa: Fix legacy probing
  2017-06-16 23:42 [PATCH net-next] net: dsa: Fix legacy probing Florian Fainelli
  2017-06-17 17:52 ` Vivien Didelot
@ 2017-06-18  3:00 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-06-18  3:00 UTC (permalink / raw)
  To: f.fainelli; +Cc: netdev, andrew, vivien.didelot, jcobham

From: Florian Fainelli <f.fainelli@gmail.com>
Date: Fri, 16 Jun 2017 16:42:11 -0700

> After commit 6d3c8c0dd88a ("net: dsa: Remove master_netdev and
> use dst->cpu_dp->netdev") and a29342e73911 ("net: dsa: Associate
> slave network device with CPU port") we would be seeing NULL pointer
> dereferences when accessing dst->cpu_dp->netdev too early. In the legacy
> code, we actually know early in advance the master network device, so
> pass it down to the relevant functions.
> 
> Fixes: 6d3c8c0dd88a ("net: dsa: Remove master_netdev and use dst->cpu_dp->netdev")
> Fixes: a29342e73911 ("net: dsa: Associate slave network device with CPU port")
> Reported-by: Jason Cobham <jcobham@questertangent.com>
> Tested-by: Jason Cobham <jcobham@questertangent.com>
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>

Applied, thanks.

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

end of thread, other threads:[~2017-06-18  3:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-16 23:42 [PATCH net-next] net: dsa: Fix legacy probing Florian Fainelli
2017-06-17 17:52 ` Vivien Didelot
2017-06-18  3:00 ` 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).