[PATCH] net: phy: Fix potential null pointer access

From: Lukas Funke
Date: Mon Nov 20 2023 - 04:33:14 EST


From: Lukas Funke <lukas.funke@xxxxxxxxxxxxxxx>

When there is no driver associated with the phydev, there will be a
nullptr access. The commit checks if the phydev driver is set before
access.

Signed-off-by: Lukas Funke <lukas.funke@xxxxxxxxxxxxxxx>
---
drivers/net/phy/phy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 1135e63a4a76..4de83e3cab77 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -136,7 +136,7 @@ EXPORT_SYMBOL(phy_print_status);
static int phy_config_interrupt(struct phy_device *phydev, bool interrupts)
{
phydev->interrupts = interrupts ? 1 : 0;
- if (phydev->drv->config_intr)
+ if (phydev->drv && phydev->drv->config_intr)
return phydev->drv->config_intr(phydev);

return 0;
--
2.30.2