net: xilinx: axienet: Fix IRQ error handling
v5 cover net: xilinx: axienet: Fix IRQ error handling
From: bui duc phuc <[email protected]>
Hi all,
This series fixes IRQ error handling in the Xilinx AXI Ethernet driver
Handle errors from optional IRQ lookup and preserve the original error codes instead of returning -ENOMEM.
The changes were found by manual code inspection and compile-tested only.
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]/
Changes in v2 :
- Split one patch from v1 into two patches.
Changes in v3 :
- Move the lp->eth_irq check below instead of handling it immediately after platform_get_irq_optional()
- Add error handling for platform_get_irq()
Changes in v4 :
- Add Reviewed-by tags
- Add error handling for irq_of_parse_and_map()
Changes in v5 :
- Change the error code returned when irq_of_parse_and_map() fails from -ENOMEM to -EINVAL.
Best regards,
Phuc
bui duc phuc (3):
net: xilinx: axienet: Propagate errors from optional IRQ lookup
net: xilinx: axienet: Handle optional IRQ return value correctly
net: xilinx: axienet: Fix IRQ error handling
drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
PATCH v5 1/3 net: xilinx: axienet: Propagate errors from optional IRQ lookup
From: bui duc phuc <[email protected]>
platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available, while other errors should be propagated.
Propagate all error codes returned by platform_get_irq_optional() other than -ENXIO.
Another call to platform_get_irq_optional() in the same function already handles the return value this way. Apply the same error handling to this call site for consistency.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -0
@@ -2975,6 +2975,8 @@ static int axienet_probe(struct platform_device *pdev)dev_err (&pdev->dev,"could not determine irqs\n" );return -ENOMEM ; } +if (lp->eth_irq <0 && lp->eth_irq != -ENXIO ) +return lp->eth_irq;/* Reset core now that clocks are enabled, prior to accessing MDIO */ ret =__axienet_device_reset (lp);
Signature · 1 line
2.43.0
PATCH v5 2/3 net: xilinx: axienet: Handle optional IRQ return value correctly
In reply to [email protected]From: bui duc phuc <[email protected]>
lp->eth_irq is assigned from platform_get_irq_optional(), which returns a non-zero interrupt number on success or a negative error number on failure. Errors other than -ENXIO are handled before this check, so -ENXIO is the only error value that can reach this point.
Check for a negative value instead of treating 0 as an undefined IRQ.
--- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1 -1
@@ -3052,7 +3052,7 @@ static int axienet_probe(struct platform_device *pdev) ndev->ethtool_ops = &axienet_ethtool_ops; }/* Check for Ethernet core IRQ (optional) */ -if (lp->eth_irq <=0 ) +if (lp->eth_irq <0 )dev_info (&pdev->dev,"Ethernet core IRQ not defined\n" );/* Retrieve the MAC address */
Signature · 1 line
2.43.0
PATCH v5 3/3 net: xilinx: axienet: Fix IRQ error handling
In reply to [email protected]From: bui duc phuc <[email protected]>
irq_of_parse_and_map() returns 0 when parsing or mapping an IRQ fails, while platform_get_irq() returns a negative error code on failure.
Handle both failure cases appropriately: return -EINVAL when irq_of_parse_and_map() fails, and propagate the original error code returned by platform_get_irq() instead of returning -ENOMEM.
---
Changes in v4 :
- Add error handling for irq_of_parse_and_map()
Changes in v5 :
- Change the error code returned when irq_of_parse_and_map() fails from -ENOMEM to -EINVAL.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6 -2
@@ -2971,10 +2971,14 @@ static int axienet_probe(struct platform_device *pdev)dev_err (&pdev->dev,"could not map DMA regs\n" );return PTR_ERR (lp->dma_regs); } -if (lp->rx_irq <=0 || lp->tx_irq <=0 ) { +if (!lp->rx_irq || !lp->tx_irq) {dev_err (&pdev->dev,"could not determine irqs\n" ); -return -ENOMEM ; +return -EINVAL ; } +if (lp->rx_irq <0 ) +return lp->rx_irq; +if (lp->tx_irq <0 ) +return lp->tx_irq;if (lp->eth_irq <0 && lp->eth_irq != -ENXIO )return lp->eth_irq;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH net-next v5 2/3] net: xilinx: axienet: Handle optional IRQ return value correctly
In reply to [email protected]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:
Critical: 0 · High: 0 · Medium: 1 (1) · Low: 0
- [Medium] net: xilinx: axienet: Handle optional IRQ return value correctly — the patch carries a Fixes: 522856cefaf0 tag and a…
Pre-existing issues:
- [Medium] DT binding vs driver interrupt indexing mismatch (pre- existing, not touched by this patch).
--
net: xilinx: axienet: Handle optional IRQ return value correctly
This changes the informational check on lp->eth_irq in axienet_probe() from "<= 0" to "< 0", on the grounds that platform_get_irq_optional() never returns 0. The patch carries a Fixes tag pointing at 522856cefaf0.
No Link: tags were present in the commit header.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev) · line 3056
Quoted 11 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +1
-1@@ -3052,7 +3052,7 @@ static int axienet_probe(struct platform_device *pdev) ndev->ethtool_ops = &axienet_ethtool_ops; }/* Check for Ethernet core IRQ (optional) */ -if (lp->eth_irq <=0 ) +if (lp->eth_irq <0 )dev_info (&pdev->dev,"Ethernet core IRQ not defined\n" );
[Severity: Medium]
Is this change a functional no-op, and if so, is the Fixes tag warranted?
The commit message itself states:
Errors other than -ENXIO are handled before this check, so -ENXIO is the only error value that can reach this point.
Combined with platform_get_irq_optional() never returning 0:
drivers/base/platform.c:platform_get_irq_affinity() {
...
out_not_found:
ret = -ENXIO;
out:
if (WARN(!ret, "0 is an invalid IRQ number\n"))
return -EINVAL;
...
}the set of values lp->eth_irq can hold when reaching this dev_info() is {positive IRQ number, -ENXIO}. Over that set, "<= 0" and "< 0" select exactly the same values, so no configuration behaves differently before or after this patch.
Would it be better to drop the Fixes tag, note that no functional change is intended, and avoid a stable backport of a change with no observable effect?
Alternatively, writing the test as:
if (lp->eth_irq == -ENXIO) dev_info(&pdev->dev, "Ethernet core IRQ not defined\n");
would state the reachable condition directly.
There is also a consistency question. Every other test of this field in the same file still uses "> 0", for example in axienet_device_reset():
axienet_iow(lp, XAE_IE_OFFSET, lp->eth_irq > 0 ?
and in axienet_init_legacy_dma():
if (lp->eth_irq > 0) {
ret = request_irq(lp->eth_irq, axienet_eth_irq, IRQF_SHARED,If treating 0 as an undefined IRQ is the problem being addressed, why are the sites that actually request and enable the interrupt left using the complementary "> 0" form, making this the only "< 0" test of eth_irq?
[Severity: Medium]
This isn't a bug introduced by this patch, but while looking at where lp->eth_irq comes from, the interrupt indexing in axienet_probe() and the binding appear to disagree.
Documentation/devicetree/bindings/net/xlnx,axi-ethernet.yaml describes a fixed item order:
interrupts:
items:
- description: Ethernet core interrupt
- description: Tx DMA interrupt
- description: Rx DMA interrupt
...
minItems: 1
but the branch in axienet_probe() that reads the DMA resources from the Ethernet node uses:
lp->rx_irq = platform_get_irq(pdev, 1); lp->tx_irq = platform_get_irq(pdev, 0); lp->eth_irq = platform_get_irq_optional(pdev, 2);
that is, index 0 = Tx DMA, 1 = Rx DMA, 2 = Ethernet core.
For a device tree written strictly to the binding in that shape, would axienet_eth_irq() end up bound to a DMA line, and the DMA handlers to the wrong lines?
The same pair also seems to disagree on minItems: 1, since this path requires index 1 unconditionally:
if (!lp->rx_irq || !lp->tx_irq) {
dev_err(&pdev->dev, "could not determine irqs\n");
return -EINVAL;
}The axistream-connected and dmas paths use platform_get_irq_optional(pdev, 0) for the Ethernet core interrupt and match the binding, and both yaml examples are consistent with the driver, so only the DMA-resources-on-the-Ethernet-node shape looks affected. There is no in-tree DTS for xlnx,axi-ethernet-* to settle which side is correct. Should the binding or the driver indexing be corrected in a separate patch?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260903073252.339250-1-phucduc.bui%40gmail.com
[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:
Critical: 0 · High: 1 · Medium: 0 (1) · Low: 0
- [High] Incomplete fix: the axistream-connected branch of axienet_probe() still cannot request a probe retry, and this patch now…
Pre-existing issues:
- [Medium] DT binding and driver disagree on interrupt index ordering.
--
net: xilinx: axienet: Fix IRQ error handling
This changes the DMA IRQ validation in axienet_probe() so that a zero result from irq_of_parse_and_map() returns -EINVAL instead of -ENOMEM, and adds explicit propagation of negative error codes coming from platform_get_irq().
Quoted 5 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev) · line 2977
Quoted 9 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2
-2@@ -2971,10 +2971,14 @@ static int axienet_probe(struct platform_device *pdev)dev_err (&pdev->dev,"could not map DMA regs\n" );return PTR_ERR (lp->dma_regs); } -if (lp->rx_irq <=0 || lp->tx_irq <=0 ) { +if (!lp->rx_irq || !lp->tx_irq) {dev_err (&pdev->dev,"could not determine irqs\n" ); -return -ENOMEM ; +return -EINVAL ; }
[Severity: High]
Does turning the zero case into a permanent -EINVAL remove the chance of a probe retry for the axistream-connected branch?
In that branch the IRQs come from:
lp->rx_irq = irq_of_parse_and_map(np, 1); lp->tx_irq = irq_of_parse_and_map(np, 0);
irq_of_parse_and_map() folds every failure into 0, including the case where the interrupt provider's IRQ domain is not registered yet:
drivers/of/irq.c:irq_of_parse_and_map() {
if (of_irq_parse_one(dev, index, &oirq))
return 0;
return irq_create_of_mapping(&oirq);
}irq_create_of_mapping() also returns 0 when no domain is found, so "not ready yet" and "malformed DT" are indistinguishable here, and axienet_probe() now converts both into a terminal -EINVAL with no -EPROBE_DEFER path.
Would of_irq_get(np, index) be a better fit? It is documented to return -EPROBE_DEFER if the IRQ domain is not yet created, and 0 only when the interrupt is genuinely absent, which would let a single pair of checks
if (irq < 0) return irq; if (!irq) return -EINVAL;
cover both the axistream and the platform_get_irq() branches.
Could the commit message also mention that the deferral case stays unhandled with irq_of_parse_and_map(), or use of_irq_get() so that it is?
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev) · line 2981
Quoted 4 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +4
-0+if (lp->rx_irq <0 ) +return lp->rx_irq; +if (lp->tx_irq <0 ) +return lp->tx_irq;
Are these two checks reachable for the axistream-connected branch? irq_of_parse_and_map() returns an unsigned int virq, so they only ever fire for the values obtained from platform_get_irq(), which makes the added error handling asymmetric between the two IRQ sources.
drivers/net/ethernet/xilinx/xilinx_axienet_main.c static int axienet_probe(struct platform_device *pdev) · line 2984
Quoted 3 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0
-0if (lp->eth_irq <0 && lp->eth_irq != -ENXIO )return lp->eth_irq;
[Severity: Medium]
This is a pre-existing issue and was not introduced by this patch, but since the patch hardens validation on exactly this branch, it may be worth
reconciling: the driver and the binding disagree on the interrupt index order.
The direct-resource branch of axienet_probe() reads:
lp->rx_irq = platform_get_irq(pdev, 1); lp->tx_irq = platform_get_irq(pdev, 0); lp->eth_irq = platform_get_irq_optional(pdev, 2);
Documentation/devicetree/bindings/net/xlnx,axi-ethernet.yaml describes the opposite positional order:
interrupts:
items:
- description: Ethernet core interrupt
- description: Tx DMA interrupt
- description: Rx DMA interrupt
The same probe function treats index 0 on the ethernet node as the Ethernet core IRQ in the axistream and dmas branches:
lp->eth_irq = platform_get_irq_optional(pdev, 0);
so index 0 has two meanings inside one function and at most one of them can match the binding.
The binding text is also self-inconsistent: it says the Ethernet core interrupt is optional while placing it first in a positional items list with
minItems: 1, which is only expressible when the optional entry is last, as the driver assumes.
For a three-interrupt DT written from the documented order, all three values are positive, so neither !lp->rx_irq || !lp->tx_irq nor the new < 0 tests reject it, and axienet_init_legacy_dma() goes on to request_irq() the Ethernet core line as a DMA handler. Should the binding or the driver be corrected so the two agree?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260903073252.339250-1-phucduc.bui%40gmail.com
Re: [PATCH net-next v5 2/3] net: xilinx: axienet: Handle optional IRQ return value correctly
In reply to [email protected]Quoted 5 lines
Critical: 0 · High: 0 · Medium: 1 (1) · Low: 0
- [Medium] net: xilinx: axienet: Handle optional IRQ return value correctly — the patch carries a
Fixes: 522856cefaf0tag and a…
OK, agreed, I'll drop the Fixes tag in this case, since this is a no-op cleanup rather than an actual behavior fix.
Quoted 4 lines
Pre-existing issues:
- [Medium] DT binding vs driver interrupt indexing mismatch (pre- existing, not touched by this patch).
This is a pre-existing issue, unrelated to this patch. I'll keep this patch's scope as is.
Quoted 6 lines
Critical: 0 · High: 1 · Medium: 0 (1) · Low: 0
- [High] Incomplete fix: the axistream-connected branch of
axienet_probe()still cannot request a probe retry, and this patch now…
irq_of_parse_and_map() has always folded every failure into plain 0, with no way to tell "not ready yet" from "malformed DT". Before this patch, that 0 was already turned into a terminal -ENOMEM, not -EPROBE_DEFER, so there was no retry path to begin with - this patch doesn't remove one, it's a pre-existing API-level limitation.
Quoted 3 lines
Pre-existing issues:
- [Medium] DT binding and driver disagree on interrupt index ordering.
This is a pre-existing issue, unrelated to this patch. I'll keep this patch's scope as is.
Re: [PATCH net-next v5 1/3] net: xilinx: axienet: Propagate errors from optional IRQ lookup
In reply to [email protected]Quoted 9 lines · On Thu, Sep 03, 2026 at 02:32:50PM +0700, [email protected] wrote:
From: bui duc phuc <[email protected]>
platform_get_irq_optional()returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ,-ENXIOindicates that no optional IRQ is available, while other errors should be propagated.Propagate all error codes returned by
platform_get_irq_optional()other than-ENXIO.
Quoted 7 lines
Another call to
platform_get_irq_optional()in the same function already handles the return value this way. Apply the same error handling to this call site for consistency.Fixes d6349e3e14c7 ("net: axienet: Mark eth_irq as optional")Reviewed-by Radhey Shyam Pandey <[email protected]>Signed-off-by bui duc phuc <[email protected]>
Re: [PATCH net-next v5 2/3] net: xilinx: axienet: Handle optional IRQ return value correctly
In reply to Bui Duc PhucQuoted 8 lines · Bui Duc Phuc
Quoted 5 lines
Critical: 0 · High: 0 · Medium: 1 (1) · Low: 0
- [Medium] net: xilinx: axienet: Handle optional IRQ return value correctly — the patch carries a
Fixes: 522856cefaf0tag and a…OK, agreed, I'll drop the Fixes tag in this case, since this is a no-op cleanup rather than an actual behavior fix.
Thanks, with that addressed this looks good to me.
Signature · 1 line
pw-bot: changes-requested
Quoted 13 lines · Bui Duc Phuc
Quoted 6 lines
Critical: 0 · High: 1 · Medium: 0 (1) · Low: 0
- [High] Incomplete fix: the axistream-connected branch of
axienet_probe()still cannot request a probe retry, and this patch now…
irq_of_parse_and_map()has always folded every failure into plain 0, with no way to tell "not ready yet" from "malformed DT". Before this patch, that 0 was already turned into a terminal-ENOMEM, not -EPROBE_DEFER, so there was no retry path to begin with - this patch doesn't remove one, it's a pre-existing API-level limitation.
Quoted 6 lines
Quoted 3 lines
Pre-existing issues:
- [Medium] DT binding and driver disagree on interrupt index ordering.This is a pre-existing issue, unrelated to this patch. I'll keep this patch's scope as is.
Thanks, agreed on both counts.
Re: [PATCH net-next v5 2/3] net: xilinx: axienet: Handle optional IRQ return value correctly
In reply to Simon HormanQuoted 7 lines
Quoted 2 lines
OK, agreed, I'll drop the Fixes tag in this case, since this is a no-op cleanup rather than an actual behavior fix.
Thanks, with that addressed this looks good to me.
Reviewed-by Simon Horman <[email protected]>
Thanks for the review, Simon.
I’ll send the updated version shortly.