Skip to contentSkip to conversation

net: dsa: exit probe if no switch were found

PATCH Superseded Neil Armstrong 2 participants 3 messages Oct 3, 2015 – Oct 6, 2015

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 5/5 net: dsa: exit probe if no switch were found

If no switch were found in dsa_setup_dst, return -ENODEV and exit the dsa_probe cleanly.

---
 net/dsa/dsa.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
net/dsa/dsa.c +15 -4
index dd171ff..9c521b7 100644
@@ -836,10 +836,11 @@ static inline void dsa_of_remove(struct device *dev)
 }
 #endif
 
-static void dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
+static int dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
 			  struct device *parent, struct dsa_platform_data *pd)
 {
 	int i;
+	unsigned configured = 0;
 
 	dst->pd = pd;
 	dst->master_netdev = dev;
@@ -859,9 +860,17 @@ static void dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
 		dst->ds[i] = ds;
 		if (ds->drv->poll_link != NULL)
 			dst->link_poll_needed = 1;
+
+		++configured;
 	}
 
 	/*
+	 * If no switch was found, exit cleanly
+	 */
+	if (!configured)
+		return -EPROBE_DEFER;
+
+	/*
 	 * If we use a tagging format that doesn't have an ethertype
 	 * field, make sure that all packets from this point on get
 	 * sent to the tag format's receive function.
@@ -877,6 +886,8 @@ static void dsa_setup_dst(struct dsa_switch_tree *dst, struct net_device *dev,
 		dst->link_poll_timer.expires = round_jiffies(jiffies + HZ);
 		add_timer(&dst->link_poll_timer);
 	}
+
+	return 0;
 }
 
 static int dsa_probe(struct platform_device *pdev)
@@ -926,9 +937,9 @@ static int dsa_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, dst);
 
-	dsa_setup_dst(dst, dev, &pdev->dev, pd);
-
-	return 0;
+	ret = dsa_setup_dst(dst, dev, &pdev->dev, pd);
+	if (!ret)
+		return 0;
 
 out:
 	dsa_of_remove(&pdev->dev);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 7 lines · Neil Armstrong

If no switch were found in dsa_setup_dst, return -ENODEV and exit the dsa_probe cleanly.

---

[snip]

net/dsa/dsa.c static int dsa_probe(struct platform_device *pdev) · line 942

Quoted 11 lines

static int dsa_probe(struct platform_device *pdev)

net/dsa/dsa.c +3 -3
@@ -926,9 +937,9 @@ static int dsa_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, dst);
 
-	dsa_setup_dst(dst, dev, &pdev->dev, pd);
-
-	return 0;
+	ret = dsa_setup_dst(dst, dev, &pdev->dev, pd);
+	if (!ret)
+		return 0;

That logic is a little weird, I would just go with something like this:

ret = dsa_setup_dst(ds, dev, &pdev->dev, pd);
if (ret)

	goto out;

return 0;

Signature · 1 line
Florian
#2 lore raw
Quoted 25 lines · Florian Fainelli
Quoted 7 lines · Neil Armstrong

If no switch were found in dsa_setup_dst, return -ENODEV and exit the dsa_probe cleanly.

---

[snip]

net/dsa/dsa.c static int dsa_probe(struct platform_device *pdev) · line 942

Quoted 11 lines

static int dsa_probe(struct platform_device *pdev)

net/dsa/dsa.c +3 -3
@@ -926,9 +937,9 @@ static int dsa_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, dst);
 
-	dsa_setup_dst(dst, dev, &pdev->dev, pd);
-
-	return 0;
+	ret = dsa_setup_dst(dst, dev, &pdev->dev, pd);
+	if (!ret)
+		return 0;

That logic is a little weird, I would just go with something like this:

Quoted 6 lines

ret = dsa_setup_dst(ds, dev, &pdev->dev, pd);
if (ret)

	goto out;

return 0;

Yes you are right, the goto out is needed to clean up the of_probe resources.

I will send a v3 with this fixed.

Neil