Thread (21 messages) flat view 21 messages, 2 authors, 2016-06-10
STALE3729d

Revision v1 of 2 in this series.

Revisions (2)
  1. v1 current
  2. v2 [diff vs current]

[PATCH net-next 8/8] net: dsa: mv88e6xxx: fail on mismatching probe

From: Vivien Didelot <hidden>
Date: 2016-06-09 00:45:59
Also in: lkml
Subsystem: networking drivers, networking [dsa], the rest · Maintainers: Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Andrew Lunn, Vladimir Oltean, Linus Torvalds

Now that we have access at probe time to the chip info described in the
device tree, check if the probed device matches the device node,
otherwise warn the user and fail.

Signed-off-by: Vivien Didelot <redacted>
---
 drivers/net/dsa/mv88e6xxx.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
index 4f07110..8244757 100644
--- a/drivers/net/dsa/mv88e6xxx.c
+++ b/drivers/net/dsa/mv88e6xxx.c
@@ -21,6 +21,7 @@
 #include <linux/list.h>
 #include <linux/mdio.h>
 #include <linux/module.h>
+#include <linux/of_device.h>
 #include <linux/of_mdio.h>
 #include <linux/netdevice.h>
 #include <linux/gpio/consumer.h>
@@ -3746,6 +3747,28 @@ static const struct of_device_id mv88e6xxx_of_id_table[] = {
 
 MODULE_DEVICE_TABLE(of, mv88e6xxx_of_id_table);
 
+static bool mv88e6xxx_of_matches(struct mv88e6xxx_priv_state *ps)
+{
+	const struct mv88e6xxx_info *info;
+	const struct of_device_id *id;
+	enum mv88e6xxx_model model;
+
+	id = of_match_device(mv88e6xxx_of_id_table, ps->dev);
+	if (!id)
+		return false;
+
+	model = (enum mv88e6xxx_model)id->data;
+	info = &mv88e6xxx_table[model];
+
+	if (ps->info->prod_num == info->prod_num)
+		return true;
+
+	dev_err(ps->dev, "described node %s mismatches probed model %s\n",
+		id->compatible, ps->info->name);
+
+	return false;
+}
+
 int mv88e6xxx_probe(struct mdio_device *mdiodev)
 {
 	struct device *dev = &mdiodev->dev;
@@ -3758,6 +3781,9 @@ int mv88e6xxx_probe(struct mdio_device *mdiodev)
 	if (!ps)
 		return -ENODEV;
 
+	if (!mv88e6xxx_of_matches(ps))
+		return -EINVAL;
+
 	ps->reset = devm_gpiod_get(dev, "reset", GPIOD_ASIS);
 	if (IS_ERR(ps->reset)) {
 		err = PTR_ERR(ps->reset);
-- 
2.8.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help