From patchwork Wed Apr 1 06:17:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 25454 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 51ADFDE087 for ; Wed, 1 Apr 2009 17:17:21 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755824AbZDAGRL (ORCPT ); Wed, 1 Apr 2009 02:17:11 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755864AbZDAGRJ (ORCPT ); Wed, 1 Apr 2009 02:17:09 -0400 Received: from rv-out-0506.google.com ([209.85.198.225]:45993 "EHLO rv-out-0506.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755442AbZDAGRG (ORCPT ); Wed, 1 Apr 2009 02:17:06 -0400 Received: by rv-out-0506.google.com with SMTP id f9so3442346rvb.1 for ; Tue, 31 Mar 2009 23:17:05 -0700 (PDT) Received: by 10.140.157.5 with SMTP id f5mr3858516rve.122.1238566625613; Tue, 31 Mar 2009 23:17:05 -0700 (PDT) Received: from trillian.cg.shawcable.net (S01060016b61d1226.cg.shawcable.net [68.146.92.145]) by mx.google.com with ESMTPS id k41sm19268735rvb.26.2009.03.31.23.17.04 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 31 Mar 2009 23:17:04 -0700 (PDT) Received: from localhost.localdomain (trillian [127.0.0.1]) by trillian.cg.shawcable.net (Postfix) with ESMTP id 1FE00C8085; Wed, 1 Apr 2009 00:17:03 -0600 (MDT) From: Grant Likely Subject: [PATCH 3/3] net/fec_mpc52xx: Don't dereference phy_device if it is NULL To: netdev@vger.kernel.org, linuxppc-dev@ozlabs.org, David Miller Date: Wed, 01 Apr 2009 00:17:03 -0600 Message-ID: <20090401061702.8641.22702.stgit@localhost.localdomain> In-Reply-To: <20090401060117.8641.32252.stgit@localhost.localdomain> References: <20090401060117.8641.32252.stgit@localhost.localdomain> User-Agent: StGIT/0.14.2 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Grant Likely The FEC Ethernet device isn't always attached to a phy. Be careful not to dereference phy_device if it is NULL. Also eliminates an unnecessary extra function from the ioctl path. Reported-by: Henk Stegeman Signed-off-by: Grant Likely --- drivers/net/fec_mpc52xx.c | 22 ++++++++++++---------- 1 files changed, 12 insertions(+), 10 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/fec_mpc52xx.c b/drivers/net/fec_mpc52xx.c index e4355d4..8bbe7f6 100644 --- a/drivers/net/fec_mpc52xx.c +++ b/drivers/net/fec_mpc52xx.c @@ -271,15 +271,6 @@ static void mpc52xx_fec_phy_stop(struct net_device *dev) phy_write(priv->phydev, MII_BMCR, BMCR_PDOWN); } -static int mpc52xx_fec_phy_mii_ioctl(struct mpc52xx_fec_priv *priv, - struct mii_ioctl_data *mii_data, int cmd) -{ - if (!priv->phydev) - return -ENOTSUPP; - - return phy_mii_ioctl(priv->phydev, mii_data, cmd); -} - static void mpc52xx_fec_phy_hw_init(struct mpc52xx_fec_priv *priv) { struct mpc52xx_fec __iomem *fec = priv->fec; @@ -852,12 +843,20 @@ 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); } @@ -887,7 +886,10 @@ static int mpc52xx_fec_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) { struct mpc52xx_fec_priv *priv = netdev_priv(dev); - return mpc52xx_fec_phy_mii_ioctl(priv, if_mii(rq), cmd); + if (!priv->phydev) + return -ENOTSUPP; + + return phy_mii_ioctl(priv->phydev, if_mii(rq), cmd); } static const struct net_device_ops mpc52xx_fec_netdev_ops = {