linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
To: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, kernel@savoirfairelinux.com,
	"David S. Miller" <davem@davemloft.net>,
	Andrew Lunn <andrew@lunn.ch>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Subject: [PATCH v2 net-next v2 05/12] net: dsa: mv88e6xxx: add switch register helpers
Date: Tue, 14 Jun 2016 14:31:46 -0400	[thread overview]
Message-ID: <20160614183153.32327-6-vivien.didelot@savoirfairelinux.com> (raw)
In-Reply-To: <20160614183153.32327-1-vivien.didelot@savoirfairelinux.com>

The mixed assignments, allocations and registrations in the probe code
make it hard to follow the logic and figure out what is DSA or chip
specific.

Extract the struct dsa_switch related code in a simple
mv88e6xxx_register_switch helper function.

For symmetry in the code, add a mv88e6xxx_unregister_switch function.

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
---
 drivers/net/dsa/mv88e6xxx.c | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/net/dsa/mv88e6xxx.c b/drivers/net/dsa/mv88e6xxx.c
index 4b4bffc..ad7735d 100644
--- a/drivers/net/dsa/mv88e6xxx.c
+++ b/drivers/net/dsa/mv88e6xxx.c
@@ -3690,30 +3690,48 @@ static struct dsa_switch_driver mv88e6xxx_switch_driver = {
 	.port_fdb_dump          = mv88e6xxx_port_fdb_dump,
 };
 
+static int mv88e6xxx_register_switch(struct mv88e6xxx_priv_state *ps,
+				     struct device_node *np)
+{
+	struct device *dev = ps->dev;
+	struct dsa_switch *ds;
+
+	ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
+	if (!ds)
+		return -ENOMEM;
+
+	ds->dev = dev;
+	ds->priv = ps;
+	ds->drv = &mv88e6xxx_switch_driver;
+
+	dev_set_drvdata(dev, ds);
+
+	return dsa_register_switch(ds, np);
+}
+
+static void mv88e6xxx_unregister_switch(struct mv88e6xxx_priv_state *ps)
+{
+	dsa_unregister_switch(ps->ds);
+}
+
 static int mv88e6xxx_probe(struct mdio_device *mdiodev)
 {
 	struct device *dev = &mdiodev->dev;
 	struct device_node *np = dev->of_node;
 	struct mv88e6xxx_priv_state *ps;
 	int id, prod_num, rev;
-	struct dsa_switch *ds;
 	u32 eeprom_len;
 	int err;
 
-	ds = devm_kzalloc(dev, sizeof(*ds) + sizeof(*ps), GFP_KERNEL);
-	if (!ds)
+	ps = devm_kzalloc(dev, sizeof(*ps), GFP_KERNEL);
+	if (!ps)
 		return -ENOMEM;
 
-	ps = (struct mv88e6xxx_priv_state *)(ds + 1);
-	ds->priv = ps;
-	ds->dev = dev;
 	ps->dev = dev;
 	ps->bus = mdiodev->bus;
 	ps->sw_addr = mdiodev->addr;
 	mutex_init(&ps->smi_mutex);
 
-	ds->drv = &mv88e6xxx_switch_driver;
-
 	id = mv88e6xxx_reg_read(ps, REG_PORT(0), PORT_SWITCH_ID);
 	if (id < 0)
 		return id;
@@ -3745,9 +3763,7 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev)
 	if (err)
 		return err;
 
-	dev_set_drvdata(dev, ds);
-
-	err = dsa_register_switch(ds, np);
+	err = mv88e6xxx_register_switch(ps, np);
 	if (err) {
 		mv88e6xxx_mdio_unregister(ps);
 		return err;
@@ -3764,8 +3780,7 @@ static void mv88e6xxx_remove(struct mdio_device *mdiodev)
 	struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev);
 	struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
 
-	dsa_unregister_switch(ds);
-
+	mv88e6xxx_unregister_switch(ps);
 	mv88e6xxx_mdio_unregister(ps);
 }
 
-- 
2.8.3

  parent reply	other threads:[~2016-06-14 18:32 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-14 18:31 [PATCH v2 net-next v2 00/12] net: dsa: mv88e6xxx: misc probe improvements Vivien Didelot
2016-06-14 18:31 ` [PATCH v2 net-next v2 01/12] net: dsa: mv88e6xxx: fix style issues Vivien Didelot
2016-06-14 21:14   ` Andrew Lunn
2016-06-14 18:31 ` [PATCH v2 net-next v2 02/12] net: dsa: mv88e6xxx: remove redundant assignments Vivien Didelot
2016-06-14 18:31 ` [PATCH v2 net-next v2 03/12] net: dsa: mv88e6xxx: use already declared variables Vivien Didelot
2016-06-14 18:31 ` [PATCH v2 net-next v2 04/12] net: dsa: mv88e6xxx: do not increment bus refcount Vivien Didelot
2016-06-14 18:31 ` Vivien Didelot [this message]
2016-06-14 21:17   ` [PATCH v2 net-next v2 05/12] net: dsa: mv88e6xxx: add switch register helpers Andrew Lunn
2016-06-14 18:31 ` [PATCH v2 net-next v2 06/12] net: dsa: mv88e6xxx: add port base address to info Vivien Didelot
2016-06-14 18:31 ` [PATCH v2 net-next v2 07/12] net: dsa: mv88e6xxx: put chip info in ID table Vivien Didelot
2016-06-14 18:31 ` [PATCH v2 net-next v2 08/12] net: dsa: mv88e6xxx: read switch ID from info Vivien Didelot
2016-06-14 18:50   ` Sergei Shtylyov
2016-06-14 21:01     ` Vivien Didelot
2016-06-14 18:31 ` [PATCH v2 net-next v2 09/12] net: dsa: mv88e6xxx: add SMI detection helper Vivien Didelot
2016-06-14 21:50   ` Andrew Lunn
2016-06-14 22:10     ` Vivien Didelot
2016-06-14 18:31 ` [PATCH v2 net-next v2 10/12] net: dsa: mv88e6xxx: iterate on compatible info Vivien Didelot
2016-06-14 19:38   ` Sergei Shtylyov
2016-06-14 21:46   ` Andrew Lunn
2016-06-14 22:13     ` Vivien Didelot
2016-06-14 18:31 ` [PATCH v2 net-next v2 11/12] net: dsa: mv88e6xxx: add an SMI ops structure Vivien Didelot
2016-06-14 22:04   ` Andrew Lunn
2016-06-14 22:26     ` Vivien Didelot
2016-06-14 18:31 ` [PATCH v2 net-next v2 12/12] net: dsa: mv88e6xxx: add addressing mode to info Vivien Didelot
2016-06-14 21:34   ` Andrew Lunn
2016-06-14 21:52     ` Vivien Didelot
2016-06-14 22:09   ` Andrew Lunn
2016-06-14 22:24     ` Vivien Didelot
2016-06-14 22:44       ` Andrew Lunn
2016-06-14 23:11         ` Vivien Didelot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160614183153.32327-6-vivien.didelot@savoirfairelinux.com \
    --to=vivien.didelot@savoirfairelinux.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=kernel@savoirfairelinux.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).