Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1417994

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

From Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Newsgroups linux.kernel
Subject [PATCH net-next 8/8] net: dsa: mv88e6xxx: fail on mismatching probe
Date 2016-06-09 02:50 +0200
Message-ID <rHWky-7lM-25@gated-at.bofh.it> (permalink)
References <rHWkx-7lM-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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 <vivien.didelot@savoirfairelinux.com>
---
 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

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH net-next 0/8] net: dsa: mv88e6xxx: misc probe improvements Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-09 02:50 +0200
  [PATCH net-next 6/8] net: dsa: mv88e6xxx: add chip detection helper Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-09 02:50 +0200
  [PATCH net-next 4/8] net: dsa: mv88e6xxx: do not increment bus refcount Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-09 02:50 +0200
    Re: [PATCH net-next 4/8] net: dsa: mv88e6xxx: do not increment bus  refcount Andrew Lunn <andrew@lunn.ch> - 2016-06-09 04:40 +0200
      Re: [PATCH net-next 4/8] net: dsa: mv88e6xxx: do not increment bus refcount Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-10 22:00 +0200
        Re: [PATCH net-next 4/8] net: dsa: mv88e6xxx: do not increment bus  refcount Andrew Lunn <andrew@lunn.ch> - 2016-06-10 22:10 +0200
  [PATCH net-next 2/8] net: dsa: mv88e6xxx: remove redundant assignments Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-09 02:50 +0200
    Re: [PATCH net-next 2/8] net: dsa: mv88e6xxx: remove redundant  assignments Andrew Lunn <andrew@lunn.ch> - 2016-06-09 04:40 +0200
  [PATCH net-next 5/8] net: dsa: mv88e6xxx: add switch register helpers Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-09 02:50 +0200
    Re: [PATCH net-next 5/8] net: dsa: mv88e6xxx: add switch register  helpers Andrew Lunn <andrew@lunn.ch> - 2016-06-09 04:40 +0200
      Re: [PATCH net-next 5/8] net: dsa: mv88e6xxx: add switch register helpers Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-09 15:00 +0200
  [PATCH net-next 3/8] net: dsa: mv88e6xxx: use already declared variables Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-09 02:50 +0200
    Re: [PATCH net-next 3/8] net: dsa: mv88e6xxx: use already declared  variables Andrew Lunn <andrew@lunn.ch> - 2016-06-09 04:40 +0200
  [PATCH net-next 8/8] net: dsa: mv88e6xxx: fail on mismatching probe Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-09 02:50 +0200
    Re: [PATCH net-next 8/8] net: dsa: mv88e6xxx: fail on mismatching  probe Andrew Lunn <andrew@lunn.ch> - 2016-06-09 04:30 +0200
      Re: [PATCH net-next 8/8] net: dsa: mv88e6xxx: fail on mismatching probe Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-10 22:40 +0200
  [PATCH net-next 7/8] net: dsa: mv88e6xxx: explicit compatible devices Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-09 02:50 +0200
    Re: [PATCH net-next 7/8] net: dsa: mv88e6xxx: explicit compatible  devices Andrew Lunn <andrew@lunn.ch> - 2016-06-09 04:20 +0200
      Re: [PATCH net-next 7/8] net: dsa: mv88e6xxx: explicit compatible devices Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-10 22:30 +0200
  [PATCH net-next 1/8] net: dsa: mv88e6xxx: fix style issues Vivien Didelot <vivien.didelot@savoirfairelinux.com> - 2016-06-09 02:50 +0200
    Re: [PATCH net-next 1/8] net: dsa: mv88e6xxx: fix style issues Andrew Lunn <andrew@lunn.ch> - 2016-06-09 04:30 +0200

csiph-web