linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Grant Likely <grant.likely@secretlab.ca>
To: linuxppc-dev@ozlabs.org, netdev@vger.kernel.org, olof@lixom.net
Cc: afleming@freescale.com, davem@davemloft.net
Subject: [PATCH v2 01/13] net: fix fec_mpc52xx driver to use net_device_ops
Date: Sat, 21 Mar 2009 16:28:16 -0600	[thread overview]
Message-ID: <20090321222815.20493.68683.stgit@localhost.localdomain> (raw)
In-Reply-To: <20090321222047.20493.87335.stgit@localhost.localdomain>

From: Henk Stegeman <henk.stegeman@gmail.com>

Fix fec_mpc52xx driver to use net_device_ops and to be careful not to
dereference phy_device if a phy has not yet been connected.

Waiting for a signed-off-by line from Henk on this one

CC: Henk Stegeman <henk.stegeman@gmail.com>
---

 drivers/net/fec_mpc52xx.c |   47 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 36 insertions(+), 11 deletions(-)


diff --git a/drivers/net/fec_mpc52xx.c b/drivers/net/fec_mpc52xx.c
index 049b0a7..3d55f9a 100644
--- a/drivers/net/fec_mpc52xx.c
+++ b/drivers/net/fec_mpc52xx.c
@@ -847,24 +847,40 @@ static void mpc52xx_fec_get_drvinfo(struct net_device *dev,
 static int mpc52xx_fec_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
 	struct mpc52xx_fec_priv *priv = netdev_priv(dev);
+
+	if (!priv->phydev)
+		return -ENODEV;
+
 	return phy_ethtool_gset(priv->phydev, cmd);
 }
 
 static int mpc52xx_fec_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
 {
 	struct mpc52xx_fec_priv *priv = netdev_priv(dev);
+
+	if (!priv->phydev)
+		return -ENODEV;
+
 	return phy_ethtool_sset(priv->phydev, cmd);
 }
 
 static u32 mpc52xx_fec_get_msglevel(struct net_device *dev)
 {
 	struct mpc52xx_fec_priv *priv = netdev_priv(dev);
+	
+	if (!priv->phydev)
+		return 0;
+
 	return priv->msg_enable;
 }
 
 static void mpc52xx_fec_set_msglevel(struct net_device *dev, u32 level)
 {
 	struct mpc52xx_fec_priv *priv = netdev_priv(dev);
+
+	if (!priv->phydev)
+		return;
+
 	priv->msg_enable = level;
 }
 
@@ -882,12 +898,31 @@ static int mpc52xx_fec_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
 	struct mpc52xx_fec_priv *priv = netdev_priv(dev);
 
+	if (!priv->phydev)
+		return -ENODEV;
+
 	return mpc52xx_fec_phy_mii_ioctl(priv, if_mii(rq), cmd);
 }
 
 /* ======================================================================== */
 /* OF Driver                                                                */
 /* ======================================================================== */
+static const struct net_device_ops mpc52xx_fec_netdev_ops = {
+	.ndo_open               = mpc52xx_fec_open,
+	.ndo_stop               = mpc52xx_fec_close,
+	.ndo_start_xmit         = mpc52xx_fec_hard_start_xmit,
+	.ndo_tx_timeout         = mpc52xx_fec_tx_timeout,
+	.ndo_get_stats          = mpc52xx_fec_get_stats,
+	.ndo_set_multicast_list = mpc52xx_fec_set_multicast_list,
+	.ndo_validate_addr      = eth_validate_addr,
+	.ndo_set_mac_address    = mpc52xx_fec_set_mac_address,
+	.ndo_do_ioctl           = mpc52xx_fec_ioctl,
+
+#ifdef CONFIG_NET_POLL_CONTROLLER
+	.ndo_poll_controller     = mpc52xx_fec_poll_controller,
+#endif
+};
+
 
 static int __devinit
 mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
@@ -929,20 +964,10 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match)
 		return -EBUSY;
 
 	/* Init ether ndev with what we have */
-	ndev->open		= mpc52xx_fec_open;
-	ndev->stop		= mpc52xx_fec_close;
-	ndev->hard_start_xmit	= mpc52xx_fec_hard_start_xmit;
-	ndev->do_ioctl		= mpc52xx_fec_ioctl;
 	ndev->ethtool_ops	= &mpc52xx_fec_ethtool_ops;
-	ndev->get_stats		= mpc52xx_fec_get_stats;
-	ndev->set_mac_address	= mpc52xx_fec_set_mac_address;
-	ndev->set_multicast_list = mpc52xx_fec_set_multicast_list;
-	ndev->tx_timeout	= mpc52xx_fec_tx_timeout;
 	ndev->watchdog_timeo	= FEC_WATCHDOG_TIMEOUT;
 	ndev->base_addr		= mem.start;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-	ndev->poll_controller = mpc52xx_fec_poll_controller;
-#endif
+	ndev->netdev_ops = &mpc52xx_fec_netdev_ops;
 
 	priv->t_irq = priv->r_irq = ndev->irq = NO_IRQ; /* IRQ are free for now */
 

  reply	other threads:[~2009-03-21 22:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-21 22:28 [PATCH v2 00/13] Rework network drivers to use of_mdio common code Grant Likely
2009-03-21 22:28 ` Grant Likely [this message]
2009-03-21 22:28 ` [PATCH v2 02/13] of: add of_parse_phandle() helper for parsing phandle properties Grant Likely
2009-03-21 22:28 ` [PATCH v2 03/13] phylib: rework to prepare for OF registration of PHYs Grant Likely
2009-03-28 16:41   ` Grant Likely
2009-03-21 22:28 ` [PATCH v2 04/13] phylib: add *_direct() variants of phy_connect and phy_attach functions Grant Likely
2009-03-21 22:28 ` [PATCH v2 05/13] openfirmware: Add OF phylib support code Grant Likely
2009-03-21 22:28 ` [PATCH v2 06/13] net: Rework mpc5200 fec driver to use of_mdio infrastructure Grant Likely
2009-03-21 22:28 ` [PATCH v2 07/13] net: Rework gianfar " Grant Likely
2009-03-21 22:28 ` [PATCH v2 08/13] net: Rework ucc_geth " Grant Likely
2009-03-21 22:29 ` [PATCH v2 09/13] net: Rework pasemi_mac " Grant Likely
2009-03-22 15:47   ` Olof Johansson
2009-03-22 18:36     ` Grant Likely
2009-03-22 20:11       ` Olof Johansson
2009-03-21 22:29 ` [PATCH v2 10/13] powerpc/82xx: Rework Embedded Planet ep8248e platform to use of_mdio Grant Likely
2009-03-21 22:29 ` [PATCH v2 11/13] net: Rework fs_enet driver to use of_mdio infrastructure Grant Likely
2009-03-21 22:29 ` [PATCH v2 12/13] powerpc/440: Hacks to ml507 .dts and Marvell PHY driver to test ll_temac Grant Likely
2009-03-21 22:29 ` [PATCH v2 13/13] net: add Xilinx ll_temac device driver Grant Likely

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=20090321222815.20493.68683.stgit@localhost.localdomain \
    --to=grant.likely@secretlab.ca \
    --cc=afleming@freescale.com \
    --cc=davem@davemloft.net \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=olof@lixom.net \
    /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).