diff mbox series

[net-next,v5,1/2] net: phy: phy_device: Prevent nullptr exceptions on ISR

Message ID 20240129135734.18975-2-andre.werner@systec-electronic.com (mailing list archive)
State Accepted
Commit 61c81872815f46006982bb80460c0c80a949b35b
Delegated to: Netdev Maintainers
Headers show
Series Prevent nullptr exceptions in ISR | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1048 this patch: 1048
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1065 this patch: 1065
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1065 this patch: 1065
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-01-31--06-00 (tests: 715)

Commit Message

Andre Werner Jan. 29, 2024, 1:55 p.m. UTC
If phydev->irq is set unconditionally, check
for valid interrupt handler or fall back to polling mode to prevent
nullptr exceptions in interrupt service routine.

Signed-off-by: Andre Werner <andre.werner@systec-electronic.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
v5:
- No functional changes. Add Reviewed-by tag.

v4:
- Delete phydev_warn and comment as suggested.

v3:
- No changes to v2. Just to complete the series.

v2:
- Add changes suggested in discussion about adin1100.c driver to
  phy_attach_direct.
---
 drivers/net/phy/phy_device.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Andrew Lunn Jan. 29, 2024, 2:29 p.m. UTC | #1
On Mon, Jan 29, 2024 at 02:55:04PM +0100, Andre Werner wrote:
> If phydev->irq is set unconditionally, check
> for valid interrupt handler or fall back to polling mode to prevent
> nullptr exceptions in interrupt service routine.
> 
> Signed-off-by: Andre Werner <andre.werner@systec-electronic.com>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>

Nitpick:

Your Signed-off-by: should go last.

Its not enough to need a respin, but please keep this in mind for
future patches.

       Andrew
Andre Werner Jan. 30, 2024, 6:54 a.m. UTC | #2
Thanks Andrew,

I will keep this in mind. Sorry!

Andre


On Mon, 29 Jan 2024, Andrew Lunn wrote:

> On Mon, Jan 29, 2024 at 02:55:04PM +0100, Andre Werner wrote:
>> If phydev->irq is set unconditionally, check
>> for valid interrupt handler or fall back to polling mode to prevent
>> nullptr exceptions in interrupt service routine.
>>
>> Signed-off-by: Andre Werner <andre.werner@systec-electronic.com>
>> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
>
> Nitpick:
>
> Your Signed-off-by: should go last.
>
> Its not enough to need a respin, but please keep this in mind for
> future patches.
>
>       Andrew
>
diff mbox series

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index dd778c7fde1d..52828d1c64f7 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1413,6 +1413,11 @@  int phy_sfp_probe(struct phy_device *phydev,
 }
 EXPORT_SYMBOL(phy_sfp_probe);
 
+static bool phy_drv_supports_irq(struct phy_driver *phydrv)
+{
+	return phydrv->config_intr && phydrv->handle_interrupt;
+}
+
 /**
  * phy_attach_direct - attach a network device to a given PHY device pointer
  * @dev: network device to attach
@@ -1527,6 +1532,9 @@  int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 	if (phydev->dev_flags & PHY_F_NO_IRQ)
 		phydev->irq = PHY_POLL;
 
+	if (!phy_drv_supports_irq(phydev->drv) && phy_interrupt_is_valid(phydev))
+		phydev->irq = PHY_POLL;
+
 	/* Port is set to PORT_TP by default and the actual PHY driver will set
 	 * it to different value depending on the PHY configuration. If we have
 	 * the generic PHY driver we can't figure it out, thus set the old
@@ -2992,11 +3000,6 @@  s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
 }
 EXPORT_SYMBOL(phy_get_internal_delay);
 
-static bool phy_drv_supports_irq(struct phy_driver *phydrv)
-{
-	return phydrv->config_intr && phydrv->handle_interrupt;
-}
-
 static int phy_led_set_brightness(struct led_classdev *led_cdev,
 				  enum led_brightness value)
 {