🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by Arina Kharlamova via B4 Relay Tue, 01 Dec 2026 19:12
[PATCH net 0/3] net: fix resource release in three old drivers
#25434
Author: Arina Kharlamova via B4 Relay
Date: Tue, 01 Dec 2026 19:12
31 lines
11772 bytes
Three small fixes for resources that probe or remove do not release
correctly: the register region of xtsonic, the net device of
xirc2ps_cs when its config fails, and the memory region of ftmac100.

I found these with spec2patch. I model-checked the probe and remove
paths of each driver with CBMC against formal specifications of the
kernel APIs they call. The specifications are checked against the kernel
source, and some of them are proved in Rocq against a transcription of
the kernel code. I also checked lock usage separately. With the help of
an AI coding assistant (Claude); I reviewed the analysis and the fix.
None of these was hit at runtime; all three were found statically.
Compile-tested only, not tested on hardware.

---
Arina Kharlamova (3):
      net: natsemi: xtsonic: fix release of the register memory region
      xirc2ps_cs: free the net device when xirc2ps_config() fails
      net: ftmac100: release the memory region with release_mem_region()

 drivers/net/ethernet/faraday/ftmac100.c  | 4 ++--
 drivers/net/ethernet/natsemi/xtsonic.c   | 9 +++++----
 drivers/net/ethernet/xircom/xirc2ps_cs.c | 7 ++++++-
 3 files changed, 13 insertions(+), 7 deletions(-)
---
base-commit: c712df600d056cc35ef7621e43c8e12513bae886
change-id: 20261201-s2p-net2-a6f815908ffc

Best regards,
--  
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
[PATCH net 1/3] net: natsemi: xtsonic: fix release of the register memory region
#25437
Author: Arina Kharlamova via B4 Relay
Date: Tue, 01 Dec 2026 19:13
67 lines
12754 bytes
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

sonic_probe1() reserves the register area with request_mem_region(),
but the error paths of sonic_probe1() and xtsonic_probe() and
xtsonic_device_remove() release it with release_region(). That looks
the range up in the I/O port resource tree, where it was never
inserted, so __release_region() prints "Trying to free nonexistent
resource" and the memory region stays reserved. The next probe of the
device then fails with -EBUSY.

sonic_probe1() also returns -ENODEV without releasing the region when
the silicon revision is not a known one.

Use release_mem_region() in all three places and leave through the
existing error label when the revision check fails.

Fixes: 74f2a5f0ef64 ("xtensa: Add support for the Sonic Ethernet device for the XT2000 board.")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
 drivers/net/ethernet/natsemi/xtsonic.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/natsemi/xtsonic.c b/drivers/net/ethernet/natsemi/xtsonic.c
index ca229c688a71..d727bf3eae76 100644
--- a/drivers/net/ethernet/natsemi/xtsonic.c
+++ b/drivers/net/ethernet/natsemi/xtsonic.c
@@ -146,7 +146,8 @@ static int sonic_probe1(struct net_device *dev)
 	if (known_revisions[i] == 0xffff) {
 		pr_info("SONIC ethernet controller not found (0x%4x)\n",
 			silicon_revision);
-		return -ENODEV;
+		err = -ENODEV;
+		goto out;
 	}
 
 	/*
@@ -187,7 +188,7 @@ static int sonic_probe1(struct net_device *dev)
 
 	return 0;
 out:
-	release_region(dev->base_addr, SONIC_MEM_SIZE);
+	release_mem_region(dev->base_addr, SONIC_MEM_SIZE);
 	return err;
 }
 
@@ -238,7 +239,7 @@ undo_probe1:
 	dma_free_coherent(lp->device,
 			  SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
 			  lp->descriptors, lp->descriptors_laddr);
-	release_region(dev->base_addr, SONIC_MEM_SIZE);
+	release_mem_region(dev->base_addr, SONIC_MEM_SIZE);
 out:
 	free_netdev(dev);
 
@@ -258,7 +259,7 @@ static void xtsonic_device_remove(struct platform_device *pdev)
 	dma_free_coherent(lp->device,
 			  SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
 			  lp->descriptors, lp->descriptors_laddr);
-	release_region (dev->base_addr, SONIC_MEM_SIZE);
+	release_mem_region(dev->base_addr, SONIC_MEM_SIZE);
 	free_netdev(dev);
 }
 

-- 
Git-157)
[PATCH net 2/3] xirc2ps_cs: free the net device when xirc2ps_config() fails
#25435
Author: Arina Kharlamova via B4 Relay
Date: Tue, 01 Dec 2026 19:13
48 lines
11994 bytes
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

xirc2ps_probe() allocates the net device with alloc_etherdev() and
returns the result of xirc2ps_config(). When xirc2ps_config() fails,
the net device is never freed. xirc2ps_detach() is the only caller of
free_netdev() and the PCMCIA core does not call the remove callback
after a failed probe.

Free the net device in xirc2ps_probe() when xirc2ps_config() returns
an error. The interrupt that was requested with the net device as
dev_id is already gone at that point, because the config_error path
calls xirc2ps_release() and pcmcia_disable_device() frees it.

Fixes: 15b99ac17295 ("[PATCH] pcmcia: add return value to _config() functions")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
 drivers/net/ethernet/xircom/xirc2ps_cs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/xircom/xirc2ps_cs.c b/drivers/net/ethernet/xircom/xirc2ps_cs.c
index 97e88886253f..4e57b7657d94 100644
--- a/drivers/net/ethernet/xircom/xirc2ps_cs.c
+++ b/drivers/net/ethernet/xircom/xirc2ps_cs.c
@@ -475,6 +475,7 @@ xirc2ps_probe(struct pcmcia_device *link)
 {
     struct net_device *dev;
     struct local_info *local;
+    int err;
 
     dev_dbg(&link->dev, "attach()\n");
 
@@ -496,7 +497,11 @@ xirc2ps_probe(struct pcmcia_device *link)
     dev->watchdog_timeo = TX_TIMEOUT;
     INIT_WORK(&local->tx_timeout_task, xirc2ps_tx_timeout_task);
 
-    return xirc2ps_config(link);
+    err = xirc2ps_config(link);
+    if (err)
+	free_netdev(dev);
+
+    return err;
 } /* xirc2ps_attach */
 
 static void

-- 
Git-157)
[PATCH net 3/3] net: ftmac100: release the memory region with release_mem_region()
#25436
Author: Arina Kharlamova via B4 Relay
Date: Tue, 01 Dec 2026 19:13
44 lines
11839 bytes
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>

ftmac100_probe() reserves the register area with request_mem_region(),
which allocates the struct resource it returns. The probe error path
and ftmac100_remove() hand that pointer to release_resource(), which
only unlinks the resource from the tree and does not free it. The
struct resource is leaked on every unbind and on every probe that
fails after the region was reserved.

Use release_mem_region(), which removes the region and frees the
struct resource.

Fixes: 8d77c036b57c ("net: add Faraday FTMAC100 10/100 Ethernet driver")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
 drivers/net/ethernet/faraday/ftmac100.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
index 40ba001d4b3f..1c23029d9e17 100644
--- a/drivers/net/ethernet/faraday/ftmac100.c
+++ b/drivers/net/ethernet/faraday/ftmac100.c
@@ -1209,7 +1209,7 @@ static int ftmac100_probe(struct platform_device *pdev)
 err_register_netdev:
 	iounmap(priv->base);
 err_ioremap:
-	release_resource(priv->res);
+	release_mem_region(res->start, resource_size(res));
 err_req_mem:
 	netif_napi_del(&priv->napi);
 defer_get_mac:
@@ -1229,7 +1229,7 @@ static void ftmac100_remove(struct platform_device *pdev)
 	unregister_netdev(netdev);
 
 	iounmap(priv->base);
-	release_resource(priv->res);
+	release_mem_region(priv->res->start, resource_size(priv->res));
 
 	netif_napi_del(&priv->napi);
 	free_netdev(netdev);

-- 
Git-157)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads