Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752787AbdHUHwu (ORCPT ); Mon, 21 Aug 2017 03:52:50 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:38962 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752671AbdHUHws (ORCPT ); Mon, 21 Aug 2017 03:52:48 -0400 From: Romain Perier To: Giuseppe Cavallaro , Alexandre Torgue , Andrew Lunn , Florian Fainelli Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Romain Perier Subject: [PATCH 2/2] net: phy: Don't use drv when it is NULL in phy_attached_print Date: Mon, 21 Aug 2017 09:52:35 +0200 Message-Id: <20170821075235.28473-3-romain.perier@collabora.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170821075235.28473-1-romain.perier@collabora.com> References: <20170821075235.28473-1-romain.perier@collabora.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1630 Lines: 49 Currently, if this logging function is used prior the phy driver is binded to the phy device (that is usually done from .ndo_open), 'phydev->drv' might be NULL, resulting in a kernel crash. That is typically the case in the stmmac driver, info about the phy is displayed during the registration of the MDIO bus, and then genphy driver is binded to this phydev when .ndo_open is called. This commit fixes the issue by using the right genphy driver, when phydev->drv is NULL. Fixes: commit fbca164776e4 ("net: stmmac: Use the right logging functi") Signed-off-by: Romain Perier --- drivers/net/phy/phy_device.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 9493fb369682..b38926bc275f 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -877,15 +877,24 @@ EXPORT_SYMBOL(phy_attached_info); #define ATTACHED_FMT "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)" void phy_attached_print(struct phy_device *phydev, const char *fmt, ...) { + struct phy_driver *drv = phydev->drv; + + if (!drv) { + if (phydev->is_c45) + drv = &genphy_10g_driver; + else + drv = &genphy_driver; + } + if (!fmt) { dev_info(&phydev->mdio.dev, ATTACHED_FMT "\n", - phydev->drv->name, phydev_name(phydev), + drv->name, phydev_name(phydev), phydev->irq); } else { va_list ap; dev_info(&phydev->mdio.dev, ATTACHED_FMT, - phydev->drv->name, phydev_name(phydev), + drv->name, phydev_name(phydev), phydev->irq); va_start(ap, fmt); -- 2.11.0