From: Andre Werner <andre.werner@systec-electronic.com>
To: andrew@lunn.ch, hkallweit1@gmail.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com
Cc: linux@armlinux.org.uk, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Andre Werner <andre.werner@systec-electronic.com>
Subject: [RFC net-next v3 1/2] net: phy: phy_device Prevent nullptr exceptions on ISR
Date: Fri, 19 Jan 2024 10:32:25 +0100 [thread overview]
Message-ID: <20240119093503.6370-1-andre.werner@systec-electronic.com> (raw)
If phydev->irq is set unconditionally by MAC drivers, check
for valid interrupt handler or fall back to polling mode to prevent
nullptr exceptions.
Signed-off-by: Andre Werner <andre.werner@systec-electronic.com>
---
v3:
- No changes to v2. Just to complete the series.
---
drivers/net/phy/phy_device.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 3611ea64875e..3986e103d25e 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,18 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
if (phydev->dev_flags & PHY_F_NO_IRQ)
phydev->irq = PHY_POLL;
+ /*
+ * Some drivers may add IRQ numbers unconditionally to a phy device that does
+ * not implement an interrupt handler after phy_probe is already done.
+ * Reset to PHY_POLL to prevent nullptr exceptions in that case.
+ */
+ if (!phy_drv_supports_irq(phydev->drv) && phy_interrupt_is_valid(phydev)) {
+ phydev_warn(phydev,
+ "No handler for IRQ=%d available. Falling back to polling mode\n",
+ phydev->irq);
+ 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 +3009,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)
{
--
2.43.0
next reply other threads:[~2024-01-19 9:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-19 9:32 Andre Werner [this message]
2024-01-19 9:32 ` [RFC net-next v3 2/2] net: phy: adin1100: Add interrupt support for link change Andre Werner
2024-01-19 9:55 ` Russell King (Oracle)
2024-01-19 13:27 ` [RFC net-next v3 1/2] net: phy: phy_device Prevent nullptr exceptions on ISR Andrew Lunn
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240119093503.6370-1-andre.werner@systec-electronic.com \
--to=andre.werner@systec-electronic.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®