From: Arina Kharlamova <arin…@mbzuai.ac.ae> ep93xx_eth_probe() maps the registers before it looks up the PHY and allocates the net_device. The early returns for a missing "phy-handle" or "reg" do not unmap them. The error path calls ep93xx_eth_remove(), which does nothing when the allocation failed, and does not unmap the registers when reserving the memory region failed, because the mapping is stored in the private data only after that. ep93xx_eth_remove() also unregisters the net_device even when register_netdev() was never called or failed: unregister_netdevice warns about a device that never was registered, or hits its BUG_ON() when registration failed after the device was marked unregistered. Unwind in probe instead: release the region, free the net_device and unmap the registers, in that order and only as far as probe got. Fixes: 770e709e38bf ("net: cirrus: add DT support for Cirrus EP93xx") Fixes: 1d22e05df818 ("[PATCH] Cirrus Logic ep93xx ethernet driver") Signed-off-by: Arina Kharlamova <arin…@mbzuai.ac.ae> --- Found by the spec2patch formal prover, with the help of an AI coding assistant (Claude); I reviewed the analysis and the fix. --- drivers/net/ethernet/cirrus/ep93xx_eth.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/cirrus/ep93xx_eth.c b/drivers/net/ethernet/cirrus/ep93xx_eth.c index a4972457edd9..8f893ed441d2 100644 --- a/drivers/net/ethernet/cirrus/ep93xx_eth.c +++ b/drivers/net/ethernet/cirrus/ep93xx_eth.c @@ -789,18 +789,22 @@ static int ep93xx_eth_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, -EIO, "Failed to ioremap ethernet registers\n"); np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0); - if (!np) - return dev_err_probe(&pdev->dev, -ENODEV, "Please provide \"phy-handle\"\n"); + if (!np) { + err = dev_err_probe(&pdev->dev, -ENODEV, "Please provide \"phy-handle\"\n"); + goto err_unmap; + } err = of_property_read_u32(np, "reg", &phy_id); of_node_put(np); - if (err) - return dev_err_probe(&pdev->dev, -ENOENT, "Failed to locate \"phy_id\"\n"); + if (err) { + err = dev_err_probe(&pdev->dev, -ENOENT, "Failed to locate \"phy_id\"\n"); + goto err_unmap; + } dev = alloc_etherdev(sizeof(struct ep93xx_priv)); if (dev == NULL) { err = -ENOMEM; - goto err_out; + goto err_unmap; } memcpy_fromio(addr, base_addr + 0x50, ETH_ALEN); @@ -821,7 +825,7 @@ static int ep93xx_eth_probe(struct platform_device *pdev) if (ep->res == NULL) { dev_err(&pdev->dev, "Could not reserve memory region\n"); err = -ENOMEM; - goto err_out; + goto err_free_netdev; } ep->base_addr = base_addr; @@ -841,7 +845,7 @@ static int ep93xx_eth_probe(struct platform_device *pdev) err = register_netdev(dev); if (err) { dev_err(&pdev->dev, "Failed to register netdev\n"); - goto err_out; + goto err_release; } printk(KERN_INFO "%s: ep93xx on-chip ethernet, IRQ %d, %pM\n", @@ -849,8 +853,12 @@ static int ep93xx_eth_probe(struct platform_device *pdev) return 0; -err_out: - ep93xx_eth_remove(pdev); +err_release: + release_mem_region(mem->start, resource_size(mem)); +err_free_netdev: + free_netdev(dev); +err_unmap: + iounmap(base_addr); return err; } --- base-commit: 25faec9ce61c01fb45abf812a222c5b43c3cd5c5 change-id: 20261129-s2p-v04-c14ecf1e0728 Best regards, -- Arina Kharlamova <arin…@mbzuai.ac.ae>