* [PATCH net v4] net: fec: Propagate PTP initialization errors
@ 2026-09-07 3:45 phucduc.bui
2026-09-07 5:42 ` Wei Fang
2026-09-08 3:45 ` sashiko-bot
0 siblings, 2 replies; 5+ messages in thread
From: phucduc.bui @ 2026-09-07 3:45 UTC (permalink / raw)
To: Wei Fang, Frank Li, Shenwei Wang
Cc: Andrew Lunn, Simon Horman, davem, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Richard Cochran, Stephen Boyd, imx, linux-kernel,
netdev, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
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.
Fixes: b86bcb299092 ("net: fec_ptp: Use platform_get_irq_xxx_optional() to avoid error message")
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
Link v1:
https://lore.kernel.org/all/20260820111416.97917-1-phucduc.bui@gmail.com/
Link v2:
https://lore.kernel.org/all/20260903092430.354186-1-phucduc.bui@gmail.com/
Link v3:
https://lore.kernel.org/all/20260904105542.70540-1-phucduc.bui@gmail.com/
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.
drivers/net/ethernet/freescale/fec.h | 2 +-
drivers/net/ethernet/freescale/fec_main.c | 18 +++++++++++++-----
drivers/net/ethernet/freescale/fec_ptp.c | 22 ++++++++++++++--------
3 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h
index 7176803146f3..8831da37326b 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -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);
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 794ec427b0ee..f7636f23d1eb 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -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)
@@ -5394,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)
diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c
index 56801c2009d5..557a76797eba 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -736,7 +736,7 @@ static irqreturn_t fec_pps_interrupt(int irq, void *dev_id)
* cyclecounter init routine and exits.
*/
-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 +779,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)
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH net v4] net: fec: Propagate PTP initialization errors
2026-09-07 3:45 [PATCH net v4] net: fec: Propagate PTP initialization errors phucduc.bui
@ 2026-09-07 5:42 ` Wei Fang
2026-09-07 12:05 ` Bui Duc Phuc
2026-09-08 3:45 ` sashiko-bot
1 sibling, 1 reply; 5+ messages in thread
From: Wei Fang @ 2026-09-07 5:42 UTC (permalink / raw)
To: phucduc.bui@gmail.com, Frank Li, Shenwei Wang
Cc: Andrew Lunn, Simon Horman, davem@davemloft.net, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Richard Cochran, Stephen Boyd,
imx@lists.linux.dev, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org
> @@ -5394,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;
> + }
> + }
This part is unrelated to PTP and inconsistent with the subject, it should be
added to a separate patch.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v4] net: fec: Propagate PTP initialization errors
2026-09-07 5:42 ` Wei Fang
@ 2026-09-07 12:05 ` Bui Duc Phuc
0 siblings, 0 replies; 5+ messages in thread
From: Bui Duc Phuc @ 2026-09-07 12:05 UTC (permalink / raw)
To: Wei Fang
Cc: Frank Li, Shenwei Wang, Andrew Lunn, Simon Horman,
davem@davemloft.net, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Richard Cochran, Stephen Boyd, imx@lists.linux.dev,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Hi Wei,
Thanks for the review.
> This part is unrelated to PTP and inconsistent with the subject, it should be
> added to a separate patch.
>
I’ll split this out into a separate patch and send it shortly.
Best regards,
Phuc
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v4] net: fec: Propagate PTP initialization errors
2026-09-07 3:45 [PATCH net v4] net: fec: Propagate PTP initialization errors phucduc.bui
2026-09-07 5:42 ` Wei Fang
@ 2026-09-08 3:45 ` sashiko-bot
2026-09-09 4:13 ` Bui Duc Phuc
1 sibling, 1 reply; 5+ messages in thread
From: sashiko-bot @ 2026-09-08 3:45 UTC (permalink / raw)
To: phucduc.bui; +Cc: Frank.Li, imx
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Use-After-Free when an interrupt fires during probe error cleanup.
--
commit c6180f28237530f0bd4b2e7e5386b744e16c2a6a
Author: bui duc phuc <phucduc.bui@gmail.com>
net: fec: Propagate PTP initialization errors
Changes fec_ptp_init() to return an error code instead of silently ignoring
failures during PTP initialization. This ensures proper propagation of
errors such as -EPROBE_DEFER.
Link: https://lore.kernel.org/all/20260820111416.97917-1-phucduc.bui@gmail.com/
Link: https://lore.kernel.org/all/20260903092430.354186-1-phucduc.bui@gmail.com/
Link: https://lore.kernel.org/all/20260904105542.70540-1-phucduc.bui@gmail.com/
> diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
> index 794ec427b0ee6..f7636f23d1ebb 100644
> --- a/drivers/net/ethernet/freescale/fec_main.c
> +++ b/drivers/net/ethernet/freescale/fec_main.c
[ ... ]
> @@ -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 is a pre-existing issue, but does jumping to the cleanup path on
fec_ptp_init() failure expose a use-after-free window?
When fec_ptp_init() successfully requests the PPS interrupt via
devm_request_irq() using ndev as dev_id, but then fails later at
ptp_clock_register(), it now returns an error back to fec_probe().
Jumping to failed_reset continues down the cleanup path:
fec_main.c:fec_probe() {
...
failed_ioremap:
free_netdev(ndev);
return ret;
}
Because the PPS interrupt is devm-managed, it won't be unregistered until
after fec_probe() returns and devres cleanup runs. If the hardware asserts
the PPS interrupt in the window between free_netdev(ndev) and devres
cleanup, won't the interrupt handler (fec_pps_interrupt) dereference the
freed ndev pointer?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260907034502.12619-1-phucduc.bui@gmail.com?part=1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v4] net: fec: Propagate PTP initialization errors
2026-09-08 3:45 ` sashiko-bot
@ 2026-09-09 4:13 ` Bui Duc Phuc
0 siblings, 0 replies; 5+ messages in thread
From: Bui Duc Phuc @ 2026-09-09 4:13 UTC (permalink / raw)
To: sashiko-reviews; +Cc: Frank.Li, imx
>
> Pre-existing issues:
> - [High] Use-After-Free when an interrupt fires during probe error cleanup.
> --
This issue is addressed here:
https://lore.kernel.org/all/20260909-fec-ptp-pps-event-uaf-v3-0-bead12c29a16@cherr.cc/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-09 4:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-07 3:45 [PATCH net v4] net: fec: Propagate PTP initialization errors phucduc.bui
2026-09-07 5:42 ` Wei Fang
2026-09-07 12:05 ` Bui Duc Phuc
2026-09-08 3:45 ` sashiko-bot
2026-09-09 4:13 ` Bui Duc Phuc
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.