net: fec: Propagate PTP initialization errors
PATCH v6 1/2 net: fec: Propagate PTP initialization errors
From: bui duc phuc <[email protected]>
Change fec_ptp_init() to return an error code instead of silently ignoring failures during PTP initialization.
The PPS IRQ is not required for the FEC/PTP functionality, so its absence should not make the probe fail. However, an unavailable optional IRQ should be distinguished from an actual error returned during the IRQ lookup.
If a platform does not support the PPS IRQ, it can omit the IRQ from its device tree and the optional lookup will return -ENXIO. Propagate other errors from the IRQ lookup instead of silently ignoring them. In particular, silently ignoring -EPROBE_DEFER can cause the driver to continue probing instead of deferring as required.
Also propagate failures from devm_request_irq() and ptp_clock_register().
Update the function declaration in fec.h accordingly.
Found by manual code inspection.
---
Link v1:
https://lore.kernel.org/all/[email protected]/
Link v2:
https://lore.kernel.org/all/[email protected]/
Link v3:
https://lore.kernel.org/all/[email protected]/
Link v4:
https://lore.kernel.org/all/[email protected]/
Link v5:
https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Squash the two patches into one.
- Add error handling for platform_get_irq_byname_optional().
- Fix error handling for ptp_clock_register().
Changes in v3:
- Retarget the patch to the net tree instead of net-next.
- Add error handling for platform_get_irq_byname_optional() in fec_probe() for the fec_enet_interrupt IRQ.
Changes in v4:
- Use a goto label for cleanup instead of returning directly on errors from platform_get_irq_byname_optional() in probe().
- Update the commit message.
Changes in v5:
- Split the optional IRQ handling in fec_main.c into a separate patch.
Changes in v6:
- Add a KDoc comment for fec_ptp_init().
- Repost this series for net-next without the Fixes: tags.
drivers/net/ethernet/freescale/fec.h | 2 +- drivers/net/ethernet/freescale/fec_main.c | 7 +++++-- drivers/net/ethernet/freescale/fec_ptp.c | 24 +++++++++++++++-------- 3 files changed, 22 insertions(+), 11 deletions(-)
drivers/net/ethernet/freescale/fec.h +1 -1
@@ -692,7 +692,7 @@ struct fec_enet_private {u64 ethtool_stats[]; }; -void fec_ptp_init (struct platform_device *pdev,int irq_idx); +int fec_ptp_init (struct platform_device *pdev,int irq_idx);void fec_ptp_restore_state (struct fec_enet_private *fep);void fec_ptp_save_state (struct fec_enet_private *fep);void fec_ptp_stop (struct platform_device *pdev);
drivers/net/ethernet/freescale/fec_main.c +5 -2
@@ -5384,8 +5384,11 @@ fec_probe(struct platform_device *pdev) goto failed_reset; irq_cnt =fec_enet_get_irq_cnt (pdev); -if (fep->bufdesc_ex) -fec_ptp_init (pdev, irq_cnt); +if (fep->bufdesc_ex) { + ret =fec_ptp_init (pdev, irq_cnt); +if (ret) + goto failed_reset; + } ret =fec_enet_init (ndev);if (ret)
drivers/net/ethernet/freescale/fec_ptp.c +16 -8
@@ -734,9 +734,11 @@ static irqreturn_t fec_pps_interrupt(int irq, void *dev_id)* This function performs the required steps for enabling ptp * support. If ptp support has already been loaded it simply calls the * cyclecounter init routine and exits. +* +* Return: 0 on success, or a negative error code on failure. */ -void fec_ptp_init (struct platform_device *pdev,int irq_idx) +int fec_ptp_init (struct platform_device *pdev,int irq_idx) {struct net_device *ndev =platform_get_drvdata (pdev);struct fec_enet_private *fep =netdev_priv (ndev);
@@ -779,26 +781,32 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx) HRTIMER_MODE_REL); irq =platform_get_irq_byname_optional (pdev,"pps" ); -if (irq <0 ) +if (irq <0 && irq != -ENXIO ) +return irq; +if (irq == -ENXIO ) { irq =platform_get_irq_optional (pdev, irq_idx); -/* Failure to get an irq is not fatal, -* only the PTP_CLOCK_PPS clock events should stop -*/ -if (irq >=0 ) { +if (irq <0 && irq != -ENXIO ) +return irq; + } + +if (irq >0 ) { ret =devm_request_irq (&pdev->dev, irq, fec_pps_interrupt,0 , pdev->name, ndev);if (ret <0 ) -dev_warn (&pdev->dev,"request for pps irq failed(%d)\n" , - ret); +return ret; } fep->ptp_clock =ptp_clock_register (&fep->ptp_caps, &pdev->dev);if (IS_ERR (fep->ptp_clock)) { + ret =PTR_ERR (fep->ptp_clock); fep->ptp_clock =NULL ;dev_err (&pdev->dev,"ptp_clock_register failed\n" ); +return ret; }schedule_delayed_work (&fep->time_keep,HZ ); + +return 0 ; }void fec_ptp_save_state (struct fec_enet_private *fep)
Signature · 1 line
2.43.0
PATCH v6 2/2 net: fec: Handle optional IRQ lookup errors correctly
From: bui duc phuc <[email protected]>
Handle errors from platform_get_irq_byname_optional() explicitly while preserving the existing fallback to platform_get_irq() when the named IRQ is not available.
Propagate errors other than -ENXIO from the optional IRQ lookup instead of silently falling back to the indexed IRQ lookup.
In particular, silently ignoring -EPROBE_DEFER can cause the driver to continue probing instead of deferring as required.
--- drivers/net/ethernet/freescale/fec_main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/net/ethernet/freescale/fec_main.c +8 -3
@@ -5397,12 +5397,17 @@ fec_probe(struct platform_device *pdev)for (i =0 ; i < irq_cnt; i++) {snprintf (irq_name,sizeof (irq_name),"int%d" , i); irq =platform_get_irq_byname_optional (pdev, irq_name); -if (irq <0 ) - irq =platform_get_irq (pdev, i); -if (irq <0 ) { +if (irq <0 && irq != -ENXIO ) { ret = irq; goto failed_irq; } +if (irq == -ENXIO ) { + irq =platform_get_irq (pdev, i); +if (irq <0 ) { + ret = irq; + goto failed_irq; + } + } ret =devm_request_irq (&pdev->dev, irq, fec_enet_interrupt,0 , pdev->name, ndev);if (ret)
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH net-next v6 2/2] net: fec: Handle optional IRQ lookup errors correctly
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Potential use-after-free of ndev in fec_enet_interrupt on probe failure. --
commit 19be3910bd7eb3aa9548563b8072044fa307b0bc
Author: bui duc phuc <[email protected]>
net: fec: Handle optional IRQ lookup errors correctly
Handle errors from platform_get_irq_byname_optional() explicitly while preserving the existing fallback to platform_get_irq() when the named IRQ is not available.
Quoted 14 lines
drivers/net/ethernet/freescale/fec_main.c +1
-3@@ -5397,12 +5397,17 @@ fec_probe(struct platform_device *pdev)for (i =0 ; i < irq_cnt; i++) {snprintf (irq_name,sizeof (irq_name),"int%d" , i); irq =platform_get_irq_byname_optional (pdev, irq_name); -if (irq <0 ) - irq =platform_get_irq (pdev, i); -if (irq <0 ) { +if (irq <0 && irq != -ENXIO ) { ret = irq; goto failed_irq;
drivers/net/ethernet/freescale/fec_main.c fec_probe(struct platform_device *pdev) · line 5412
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +7
-0} +if (irq == -ENXIO ) { + irq =platform_get_irq (pdev, i); +if (irq <0 ) { + ret = irq; + goto failed_irq; + } + } ret =devm_request_irq (&pdev->dev, irq, fec_enet_interrupt,0 , pdev->name, ndev);
[Severity: High]
This is a pre-existing issue, but does this create a potential use-after-free if a subsequent step in the probe path fails?
Because this interrupt is requested via devm_request_irq(), it won't be unregistered until after the probe function returns and devres cleanup runs.
However, the probe error path explicitly frees the network device:
drivers/net/ethernet/freescale/fec_main.c:fec_probe() {
...
failed_ioremap:
free_netdev(ndev);
return ret;
}Does this leave a window where an interrupt could fire (e.g., from a shared IRQ line or pending hardware event) while we are returning from probe, causing fec_enet_interrupt() to access the freed ndev pointer?
Quoted 1 line
drivers/net/ethernet/freescale/fec_main.c +0
-0if (ret)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Unsafe error paths leave the devm-managed PPS IRQ active while hardware clocks are disabled and ndev is freed. --
commit 4a112d5fbd55881d0083cd7c88b9d35cd673b462
Author: bui duc phuc <[email protected]>
net: fec: Propagate PTP initialization errors
This commit changes fec_ptp_init() to return an error code instead of silently ignoring failures during PTP initialization. It also propagates failures from devm_request_irq() and ptp_clock_register().
Quoted 3 lines
drivers/net/ethernet/freescale/fec_main.c +0
-0
[ ... ]
drivers/net/ethernet/freescale/fec_main.c fec_probe(struct platform_device *pdev) · line 5390
Quoted 10 lines
drivers/net/ethernet/freescale/fec_main.c +4
-2@@ -5384,8 +5384,11 @@ fec_probe(struct platform_device *pdev) goto failed_reset; irq_cnt =fec_enet_get_irq_cnt (pdev); -if (fep->bufdesc_ex) -fec_ptp_init (pdev, irq_cnt); +if (fep->bufdesc_ex) { + ret =fec_ptp_init (pdev, irq_cnt); +if (ret) + goto failed_reset;
[Severity: High]
This isn't a bug introduced by this patch, but this new error path exposes a pre-existing issue.
If fec_ptp_init() fails (for example, when ptp_clock_register() returns an error), we jump straight to failed_reset. At this point, the PPS interrupt has already been requested via devm_request_irq() inside fec_ptp_init().
The cleanup path under failed_reset disables hardware clocks (clk_ahb, clk_ipg) and eventually frees ndev. Since the devm-managed IRQ is not freed until fec_probe() returns, the interrupt remains active during this cleanup.
If a pending PPS interrupt fires during this window, fec_pps_interrupt() will access hardware registers with clocks disabled and dereference the freed ndev memory. Could this lead to a kernel panic or use-after-free during a probe failure?
Quoted 4 lines
drivers/net/ethernet/freescale/fec_main.c +1
-0+ } ret =fec_enet_init (ndev);if (ret)
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Fri, 11 Sep 2026 11:00:20 +0700 you wrote:
From: bui duc phuc <[email protected]>
Change
fec_ptp_init()to return an error code instead of silently ignoring failures during PTP initialization.The PPS IRQ is not required for the FEC/PTP functionality, so its absence should not make the probe fail. However, an unavailable optional IRQ should be distinguished from an actual error returned during the IRQ lookup.
[...]
Here is the summary with links:
- [net-next,v6,1/2] net: fec: Propagate PTP initialization errors
https://git.kernel.org/netdev/net-next/c/2343cff0b382 - [net-next,v6,2/2] net: fec: Handle optional IRQ lookup errors correctly https://git.kernel.org/netdev/net-next/c/20d1b74a32d0
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html