diff mbox series

net: ftgmac100: use bus name in mdio error messages

Message ID 20220517221639.18912-1-zev@bewilderbeest.net
State Accepted
Commit f44bf737841bb90a92b6c7eca9a8ee4075febe57
Delegated to: Tom Rini
Headers show
Series net: ftgmac100: use bus name in mdio error messages | expand

Commit Message

Zev Weiss May 17, 2022, 10:16 p.m. UTC
Previously we'd been using a device name retrieved via
ftgmac100_data->phydev, but the mdio read/write functions may be
called before that member is initialized in ftgmac100_phy_init(),
leading to a NULL pointer dereference while printing the error message
issued if the mdio access fails.  We can instead use bus->name, which
is already available at that point.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Fixes: 538e75d3fc54 ("net: ftgmac100: add MDIO bus and phylib support")
---
 drivers/net/ftgmac100.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Cédric Le Goater May 18, 2022, 4:45 a.m. UTC | #1
On 5/18/22 00:16, Zev Weiss wrote:
> Previously we'd been using a device name retrieved via
> ftgmac100_data->phydev, but the mdio read/write functions may be
> called before that member is initialized in ftgmac100_phy_init(),
> leading to a NULL pointer dereference while printing the error message
> issued if the mdio access fails.  We can instead use bus->name, which
> is already available at that point.
> 
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
> Fixes: 538e75d3fc54 ("net: ftgmac100: add MDIO bus and phylib support")
Reviewed-by: Cédric Le Goater <clg@kaod.org>

Thanks,

C.


> ---
>   drivers/net/ftgmac100.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c
> index 78779d7d60b9..74261d14e548 100644
> --- a/drivers/net/ftgmac100.c
> +++ b/drivers/net/ftgmac100.c
> @@ -119,7 +119,7 @@ static int ftgmac100_mdio_read(struct mii_dev *bus, int phy_addr, int dev_addr,
>   				 FTGMAC100_MDIO_TIMEOUT_USEC);
>   	if (ret) {
>   		pr_err("%s: mdio read failed (phy:%d reg:%x)\n",
> -		       priv->phydev->dev->name, phy_addr, reg_addr);
> +		       bus->name, phy_addr, reg_addr);
>   		return ret;
>   	}
>   
> @@ -151,7 +151,7 @@ static int ftgmac100_mdio_write(struct mii_dev *bus, int phy_addr, int dev_addr,
>   				 FTGMAC100_MDIO_TIMEOUT_USEC);
>   	if (ret) {
>   		pr_err("%s: mdio write failed (phy:%d reg:%x)\n",
> -		       priv->phydev->dev->name, phy_addr, reg_addr);
> +		       bus->name, phy_addr, reg_addr);
>   	}
>   
>   	return ret;
Tom Rini Aug. 8, 2022, 7:08 p.m. UTC | #2
On Tue, May 17, 2022 at 03:16:39PM -0700, Zev Weiss wrote:

> Previously we'd been using a device name retrieved via
> ftgmac100_data->phydev, but the mdio read/write functions may be
> called before that member is initialized in ftgmac100_phy_init(),
> leading to a NULL pointer dereference while printing the error message
> issued if the mdio access fails.  We can instead use bus->name, which
> is already available at that point.
> 
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
> Fixes: 538e75d3fc54 ("net: ftgmac100: add MDIO bus and phylib support")
> Reviewed-by: Cédric Le Goater <clg@kaod.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c
index 78779d7d60b9..74261d14e548 100644
--- a/drivers/net/ftgmac100.c
+++ b/drivers/net/ftgmac100.c
@@ -119,7 +119,7 @@  static int ftgmac100_mdio_read(struct mii_dev *bus, int phy_addr, int dev_addr,
 				 FTGMAC100_MDIO_TIMEOUT_USEC);
 	if (ret) {
 		pr_err("%s: mdio read failed (phy:%d reg:%x)\n",
-		       priv->phydev->dev->name, phy_addr, reg_addr);
+		       bus->name, phy_addr, reg_addr);
 		return ret;
 	}
 
@@ -151,7 +151,7 @@  static int ftgmac100_mdio_write(struct mii_dev *bus, int phy_addr, int dev_addr,
 				 FTGMAC100_MDIO_TIMEOUT_USEC);
 	if (ret) {
 		pr_err("%s: mdio write failed (phy:%d reg:%x)\n",
-		       priv->phydev->dev->name, phy_addr, reg_addr);
+		       bus->name, phy_addr, reg_addr);
 	}
 
 	return ret;