netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] net: phy: Fix possible NULL pointer dereference issues caused by phy_attached_info_irq
@ 2024-01-15  8:50 Kunwu Chan
  2024-01-15 11:28 ` Russell King (Oracle)
  0 siblings, 1 reply; 2+ messages in thread
From: Kunwu Chan @ 2024-01-15  8:50 UTC (permalink / raw)
  To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni
  Cc: f.fainelli, netdev, linux-kernel, Kunwu Chan

kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.

phylink_bringup_phy needs to be done, otherwise network interface is
likely to be dead, so when irq_str is NULL, just print an empty string.

Fixes: e27f178793de ("net: phy: Added IRQ print to phylink_bringup_phy()")
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
Suggested-by: Andrew Lunn <andrew@lunn.ch>
---
v2: Print empty string when irq_str is NULL in phylink_bringup_phy
---
 drivers/net/phy/phy_device.c | 3 +++
 drivers/net/phy/phylink.c    | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 3611ea64875e..10fa99d957c0 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1299,6 +1299,9 @@ void phy_attached_print(struct phy_device *phydev, const char *fmt, ...)
 	const char *unbound = phydev->drv ? "" : "[unbound] ";
 	char *irq_str = phy_attached_info_irq(phydev);
 
+	if (!irq_str)
+		return;
+
 	if (!fmt) {
 		phydev_info(phydev, ATTACHED_FMT "\n", unbound,
 			    phydev_name(phydev), irq_str);
diff --git a/drivers/net/phy/phylink.c b/drivers/net/phy/phylink.c
index ed0b4ccaa6a6..819574a06036 100644
--- a/drivers/net/phy/phylink.c
+++ b/drivers/net/phy/phylink.c
@@ -1886,7 +1886,7 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy,
 	irq_str = phy_attached_info_irq(phy);
 	phylink_info(pl,
 		     "PHY [%s] driver [%s] (irq=%s)\n",
-		     dev_name(&phy->mdio.dev), phy->drv->name, irq_str);
+		     dev_name(&phy->mdio.dev), phy->drv->name, irq_str ? irq_str : "");
 	kfree(irq_str);
 
 	mutex_lock(&phy->lock);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-15 11:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-15  8:50 [PATCH net v2] net: phy: Fix possible NULL pointer dereference issues caused by phy_attached_info_irq Kunwu Chan
2024-01-15 11:28 ` Russell King (Oracle)

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).