From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752741AbdDJXdh (ORCPT ); Mon, 10 Apr 2017 19:33:37 -0400 Received: from fllnx210.ext.ti.com ([198.47.19.17]:30451 "EHLO fllnx210.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751564AbdDJXdg (ORCPT ); Mon, 10 Apr 2017 19:33:36 -0400 From: Grygorii Strashko To: "David S. Miller" , , Andrew Lunn , Florian Fainelli CC: Sekhar Nori , , Grygorii Strashko Subject: [PATCH] net: phy: micrel: KSZ9031: fix crash when statistic requested Date: Mon, 10 Apr 2017 18:33:24 -0500 Message-ID: <20170410233324.1178-1-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.10.1 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now the command: ethtool --phy-statistics eth0 will cause system crash with meassage "Unable to handle kernel NULL pointer dereference at virtual address 00000010" from: (kszphy_get_stats) from [] (ethtool_get_phy_stats+0xd8/0x210) (ethtool_get_phy_stats) from [] (dev_ethtool+0x5b8/0x228c) (dev_ethtool) from [] (dev_ioctl+0x3fc/0x964) (dev_ioctl) from [] (sock_ioctl+0x170/0x2c0) (sock_ioctl) from [] (do_vfs_ioctl+0xa8/0x95c) (do_vfs_ioctl) from [] (SyS_ioctl+0x3c/0x64) (SyS_ioctl) from [] (ret_fast_syscall+0x0/0x44) The reason: phy_driver structure for KSZ9031 phy has no .probe() callback defined. As result, struct phy_device *phydev->priv pointer will not be initializes (null). Fix it by adding additional checks for !phydev->priv in kszphy_get_stats(), kszphy_get_strings() and kszphy_get_sset_count() Fixes: 2b2427d06426 ("phy: micrel: Add ethtool statistics counters") Signed-off-by: Grygorii Strashko --- drivers/net/phy/micrel.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 6742070..8dbc1be 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -574,7 +574,6 @@ static int ksz9031_config_init(struct phy_device *phydev) MII_KSZ9031RN_TX_DATA_PAD_SKEW, 4, tx_data_skews, 4); } - return ksz9031_center_flp_timing(phydev); } @@ -654,6 +653,9 @@ ksz9021_wr_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum, static int kszphy_get_sset_count(struct phy_device *phydev) { + if (!phydev->priv) + return -EOPNOTSUPP; + return ARRAY_SIZE(kszphy_hw_stats); } @@ -661,6 +663,9 @@ static void kszphy_get_strings(struct phy_device *phydev, u8 *data) { int i; + if (!phydev->priv) + return; + for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) { memcpy(data + i * ETH_GSTRING_LEN, kszphy_hw_stats[i].string, ETH_GSTRING_LEN); @@ -694,6 +699,9 @@ static void kszphy_get_stats(struct phy_device *phydev, { int i; + if (!phydev->priv) + return; + for (i = 0; i < ARRAY_SIZE(kszphy_hw_stats); i++) data[i] = kszphy_get_stat(phydev, i); } -- 2.10.1