Thread View: linux.kernel.netdev
6 messages
6 total messages
Started by Arina Kharlamova via B4 Relay
Tue, 01 Dec 2026 19:13
[PATCH net 0/5] net: free per-open allocations and interrupts
Author: Arina Kharlamova via B4 Relay
Date: Tue, 01 Dec 2026 19:13
Date: Tue, 01 Dec 2026 19:13
40 lines
12297 bytes
12297 bytes
These drivers allocate memory or request interrupts with devm in
ndo_open or in the line discipline open, so every open leaves them
behind until the device is unbound. In sxgbe every open after the
first one then fails with -EBUSY.
I found this with spec2patch. I model-checked the probe and remove paths
of the driver with CBMC against formal specifications of the kernel APIs
it calls. 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.
Compile-tested only, not tested on hardware.
The other 2014 sxgbe authors' addresses are no longer valid, so they are
not in Cc.
To: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
Arina Kharlamova (5):
net: rtsn: fix irq name leak in rtsn_request_irq()
net: sxgbe: free the interrupts in sxgbe_release()
net: sxgbe: free the TX ring arrays in free_tx_ring()
net: ll_temac: fix rx_skb leak in temac_dma_bd_init()
nfc: nfcmrvl: do not use devres for the reset GPIO
drivers/net/ethernet/renesas/rtsn.c | 13 +++---
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 60 +++++++++++++++++--------
drivers/net/ethernet/xilinx/ll_temac_main.c | 8 ++--
drivers/nfc/nfcmrvl/main.c | 9 +++-
drivers/nfc/nfcmrvl/uart.c | 15 +++----
5 files changed, 67 insertions(+), 38 deletions(-)
---
base-commit: c712df600d056cc35ef7621e43c8e12513bae886
change-id: 20261201-s2p-lpr-net-fffd7804d1b3
Best regards,
--
Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
[PATCH net 1/5] net: rtsn: fix irq name leak in rtsn_request_irq()
Author: Arina Kharlamova via B4 Relay
Date: Tue, 01 Dec 2026 19:13
Date: Tue, 01 Dec 2026 19:13
62 lines
12468 bytes
12468 bytes
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
rtsn_request_irq() runs on every ndo_open and allocates the irq name
with devm_kasprintf() on the platform device. rtsn_free_irqs() only
calls free_irq(), so every open leaves two names allocated until the
driver is unbound.
Allocate the name with kasprintf() and free the pointer that
free_irq() returns. Also free it when request_irq() fails.
Fixes: b0d3969d2b4d ("net: ethernet: rtsn: Add support for Renesas Ethernet-TSN")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
drivers/net/ethernet/renesas/rtsn.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/renesas/rtsn.c b/drivers/net/ethernet/renesas/rtsn.c
index f7beeb73eb16..4e4d356f6466 100644
--- a/drivers/net/ethernet/renesas/rtsn.c
+++ b/drivers/net/ethernet/renesas/rtsn.c
@@ -514,22 +514,23 @@ static int rtsn_request_irq(unsigned int irq, irq_handler_t handler,
char *name;
int ret;
- name = devm_kasprintf(&priv->pdev->dev, GFP_KERNEL, "%s:%s",
- priv->ndev->name, ch);
+ name = kasprintf(GFP_KERNEL, "%s:%s", priv->ndev->name, ch);
if (!name)
return -ENOMEM;
ret = request_irq(irq, handler, flags, name, priv);
- if (ret)
+ if (ret) {
netdev_err(priv->ndev, "Cannot request IRQ %s\n", name);
+ kfree(name);
+ }
return ret;
}
static void rtsn_free_irqs(struct rtsn_private *priv)
{
- free_irq(priv->tx_data_irq, priv);
- free_irq(priv->rx_data_irq, priv);
+ kfree(free_irq(priv->tx_data_irq, priv));
+ kfree(free_irq(priv->rx_data_irq, priv));
}
static int rtsn_request_irqs(struct rtsn_private *priv)
@@ -550,7 +551,7 @@ static int rtsn_request_irqs(struct rtsn_private *priv)
ret = rtsn_request_irq(priv->rx_data_irq, rtsn_irq, 0, priv, "rx");
if (ret) {
- free_irq(priv->tx_data_irq, priv);
+ kfree(free_irq(priv->tx_data_irq, priv));
return ret;
}
--
Git-157)
[PATCH net 2/5] net: sxgbe: free the interrupts in sxgbe_release()
Author: Arina Kharlamova via B4 Relay
Date: Tue, 01 Dec 2026 19:13
Date: Tue, 01 Dec 2026 19:13
130 lines
15116 bytes
15116 bytes
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
sxgbe_open() requests its interrupts with devm_request_irq(), and
neither sxgbe_release() nor the error path of sxgbe_open() frees them.
The handlers stay installed after the interface is stopped, and the
next sxgbe_open() fails with -EBUSY on the first TX queue interrupt,
which is not shared. The interface cannot be brought up again until
the driver is rebound.
Use request_irq() and free the interrupts in sxgbe_release() and on
the error path of sxgbe_open().
Fixes: 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 50 +++++++++++++++++--------
1 file changed, 34 insertions(+), 16 deletions(-)
diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
index f2fecc3bcea1..4a7d149149ad 100644
--- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
+++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
@@ -1100,8 +1100,8 @@ static int sxgbe_open(struct net_device *dev)
}
/* Request the IRQ lines */
- ret = devm_request_irq(priv->device, priv->irq, sxgbe_common_interrupt,
- IRQF_SHARED, dev->name, dev);
+ ret = request_irq(priv->irq, sxgbe_common_interrupt,
+ IRQF_SHARED, dev->name, dev);
if (unlikely(ret < 0)) {
netdev_err(dev, "%s: ERROR: allocating the IRQ %d (error: %d)\n",
__func__, priv->irq, ret);
@@ -1112,39 +1112,36 @@ static int sxgbe_open(struct net_device *dev)
* register a dedicated handler
*/
if (priv->lpi_irq != dev->irq) {
- ret = devm_request_irq(priv->device, priv->lpi_irq,
- sxgbe_common_interrupt,
- IRQF_SHARED, dev->name, dev);
+ ret = request_irq(priv->lpi_irq, sxgbe_common_interrupt,
+ IRQF_SHARED, dev->name, dev);
if (unlikely(ret < 0)) {
netdev_err(dev, "%s: ERROR: allocating the LPI IRQ %d (%d)\n",
__func__, priv->lpi_irq, ret);
- goto init_error;
+ goto lpi_irq_error;
}
}
/* Request TX DMA irq lines */
SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num) {
- ret = devm_request_irq(priv->device,
- (priv->txq[queue_num])->irq_no,
- sxgbe_tx_interrupt, 0,
- dev->name, priv->txq[queue_num]);
+ ret = request_irq((priv->txq[queue_num])->irq_no,
+ sxgbe_tx_interrupt, 0,
+ dev->name, priv->txq[queue_num]);
if (unlikely(ret < 0)) {
netdev_err(dev, "%s: ERROR: allocating TX IRQ %d (error: %d)\n",
__func__, priv->irq, ret);
- goto init_error;
+ goto tx_irq_error;
}
}
/* Request RX DMA irq lines */
SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num) {
- ret = devm_request_irq(priv->device,
- (priv->rxq[queue_num])->irq_no,
- sxgbe_rx_interrupt, 0,
- dev->name, priv->rxq[queue_num]);
+ ret = request_irq((priv->rxq[queue_num])->irq_no,
+ sxgbe_rx_interrupt, 0,
+ dev->name, priv->rxq[queue_num]);
if (unlikely(ret < 0)) {
netdev_err(dev, "%s: ERROR: allocating TX IRQ %d (error: %d)\n",
__func__, priv->irq, ret);
- goto init_error;
+ goto rx_irq_error;
}
}
@@ -1185,6 +1182,17 @@ static int sxgbe_open(struct net_device *dev)
return 0;
+rx_irq_error:
+ while (queue_num--)
+ free_irq(priv->rxq[queue_num]->irq_no, priv->rxq[queue_num]);
+ queue_num = SXGBE_TX_QUEUES;
+tx_irq_error:
+ while (queue_num--)
+ free_irq(priv->txq[queue_num]->irq_no, priv->txq[queue_num]);
+ if (priv->lpi_irq != dev->irq)
+ free_irq(priv->lpi_irq, dev);
+lpi_irq_error:
+ free_irq(priv->irq, dev);
init_error:
free_dma_desc_resources(priv);
init_phy_error:
@@ -1205,6 +1213,7 @@ phy_error:
static int sxgbe_release(struct net_device *dev)
{
struct sxgbe_priv_data *priv = netdev_priv(dev);
+ int queue_num;
if (priv->eee_enabled)
timer_delete_sync(&priv->eee_ctrl_timer);
@@ -1229,6 +1238,15 @@ static int sxgbe_release(struct net_device *dev)
/* disable MTL queue */
sxgbe_disable_mtl_engine(priv);
+ /* Free the IRQ lines */
+ SXGBE_FOR_EACH_QUEUE(SXGBE_RX_QUEUES, queue_num)
+ free_irq(priv->rxq[queue_num]->irq_no, priv->rxq[queue_num]);
+ SXGBE_FOR_EACH_QUEUE(SXGBE_TX_QUEUES, queue_num)
+ free_irq(priv->txq[queue_num]->irq_no, priv->txq[queue_num]);
+ if (priv->lpi_irq != dev->irq)
+ free_irq(priv->lpi_irq, dev);
+ free_irq(priv->irq, dev);
+
/* Release and free the Rx/Tx resources */
free_dma_desc_resources(priv);
--
Git-157)
[PATCH net 3/5] net: sxgbe: free the TX ring arrays in free_tx_ring()
Author: Arina Kharlamova via B4 Relay
Date: Tue, 01 Dec 2026 19:13
Date: Tue, 01 Dec 2026 19:13
61 lines
12725 bytes
12725 bytes
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
init_tx_ring() runs on every sxgbe_open() and allocates the tx_skbuff
and tx_skbuff_dma arrays of each TX queue with devm. free_tx_ring()
frees only the descriptor ring, so the arrays of every open stay
allocated until the driver is unbound.
Allocate the arrays with kzalloc_objs() and free them in
free_tx_ring() and on the error path of init_tx_ring(), as the RX
side already does.
Fixes: 1edb9ca69e8a ("net: sxgbe: add basic framework for Samsung 10Gb ethernet driver")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
index 4a7d149149ad..da8215307502 100644
--- a/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
+++ b/drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c
@@ -408,14 +408,14 @@ static int init_tx_ring(struct device *dev, u8 queue_no,
return -ENOMEM;
/* allocate memory for TX skbuff array */
- tx_ring->tx_skbuff_dma = devm_kzalloc_objs(dev, dma_addr_t, tx_rsize);
+ tx_ring->tx_skbuff_dma = kzalloc_objs(dma_addr_t, tx_rsize);
if (!tx_ring->tx_skbuff_dma)
goto dmamem_err;
- tx_ring->tx_skbuff = devm_kzalloc_objs(dev, struct sk_buff *, tx_rsize);
+ tx_ring->tx_skbuff = kzalloc_objs(struct sk_buff *, tx_rsize);
if (!tx_ring->tx_skbuff)
- goto dmamem_err;
+ goto skbuff_dma_err;
/* assign queue number */
tx_ring->queue_no = queue_no;
@@ -426,6 +426,8 @@ static int init_tx_ring(struct device *dev, u8 queue_no,
return 0;
+skbuff_dma_err:
+ kfree(tx_ring->tx_skbuff_dma);
dmamem_err:
dma_free_coherent(dev, tx_rsize * sizeof(struct sxgbe_tx_norm_desc),
tx_ring->dma_tx, tx_ring->dma_tx_phy);
@@ -545,6 +547,8 @@ static void free_tx_ring(struct device *dev, struct sxgbe_tx_queue *tx_ring,
{
dma_free_coherent(dev, tx_rsize * sizeof(struct sxgbe_tx_norm_desc),
tx_ring->dma_tx, tx_ring->dma_tx_phy);
+ kfree(tx_ring->tx_skbuff_dma);
+ kfree(tx_ring->tx_skbuff);
}
/**
--
Git-157)
[PATCH net 4/5] net: ll_temac: fix rx_skb leak in temac_dma_bd_init()
Author: Arina Kharlamova via B4 Relay
Date: Tue, 01 Dec 2026 19:13
Date: Tue, 01 Dec 2026 19:13
48 lines
12439 bytes
12439 bytes
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
temac_dma_bd_init() runs on every ndo_open and allocates the rx_skb
array with devm on the net device. temac_dma_bd_release() does not
free it, so every open leaves one array allocated until the device is
removed.
Allocate the array once in temac_probe(), sized for RX_BD_NUM_MAX, the
largest ring that set_ringparam accepts, and clear the entries in use
in temac_dma_bd_init(). temac_dma_bd_release() stops at the first NULL
entry, so stale pointers from the previous open must not remain.
Fixes: a63625d2a0e7 ("net: ll_temac: Fix and simplify error handling by using devres functions")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
drivers/net/ethernet/xilinx/ll_temac_main.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
index 45d16464c2e8..2ce4f8e944df 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -329,9 +329,7 @@ static int temac_dma_bd_init(struct net_device *ndev)
dma_addr_t skb_dma_addr;
int i;
- lp->rx_skb = devm_kzalloc_objs(&ndev->dev, *lp->rx_skb, lp->rx_bd_num);
- if (!lp->rx_skb)
- goto out;
+ memset(lp->rx_skb, 0, sizeof(*lp->rx_skb) * lp->rx_bd_num);
/* allocate the tx and rx ring buffer descriptors. */
/* returns a virtual address and a physical address. */
@@ -1424,6 +1422,10 @@ static int temac_probe(struct platform_device *pdev)
spin_lock_init(&lp->rx_lock);
INIT_DELAYED_WORK(&lp->restart_work, ll_temac_restart_work_func);
+ lp->rx_skb = devm_kzalloc_objs(&pdev->dev, *lp->rx_skb, RX_BD_NUM_MAX);
+ if (!lp->rx_skb)
+ return -ENOMEM;
+
/* Setup mutex for synchronization of indirect register access */
if (pdata) {
if (!pdata->indirect_lock) {
--
Git-157)
[PATCH net 5/5] nfc: nfcmrvl: do not use devres for the reset GPIO
Author: Arina Kharlamova via B4 Relay
Date: Tue, 01 Dec 2026 19:13
Date: Tue, 01 Dec 2026 19:13
112 lines
14517 bytes
14517 bytes
From: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
nfcmrvl_nci_uart_open() runs every time the N_NCI line discipline is
set and passes the tty device to the code that requests the reset GPIO
with devm helpers. The tty device outlives the line discipline, and
nfcmrvl_nci_uart_close() does not release the GPIO. The next open gets
-EBUSY and falls back to the module parameters, without the reset line
and without the DT settings.
This needs a marvell,nfc-uart child node under the UART and a kernel
without serdev ttyport (SERIAL_DEV_CTRL_TTYPORT=n).
Commit 0cbe40112f42 ("NFC: nfcmrvl: do not use device-managed
resources") removed devres from this driver for this reason, and the
conversion to GPIO descriptors brought it back.
Request the GPIO with the unmanaged helpers and put it in
nfcmrvl_nci_unregister_dev() and in the error paths of
nfcmrvl_nci_register_dev().
Fixes: 253350dbf3e7 ("nfc: nfcmrvl: convert to gpio descriptors")
Signed-off-by: Arina Kharlamova <arina.kharlamova@mbzuai.ac.ae>
---
drivers/nfc/nfcmrvl/main.c | 9 +++++++--
drivers/nfc/nfcmrvl/uart.c | 15 +++++++--------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/nfc/nfcmrvl/main.c b/drivers/nfc/nfcmrvl/main.c
index 6efa83219117..0e2a7f8353b2 100644
--- a/drivers/nfc/nfcmrvl/main.c
+++ b/drivers/nfc/nfcmrvl/main.c
@@ -102,8 +102,10 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy,
u32 protocols;
priv = kzalloc_obj(*priv);
- if (!priv)
+ if (!priv) {
+ gpiod_put(pdata->reset_gpio);
return ERR_PTR(-ENOMEM);
+ }
priv->drv_data = drv_data;
priv->if_ops = ops;
@@ -114,7 +116,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy,
if (!priv->config.reset_gpio) {
priv->config.reset_gpio =
- devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
+ gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
if (IS_ERR(priv->config.reset_gpio)) {
priv->config.reset_gpio = NULL;
nfc_err(dev, "failed to get reset gpio\n");
@@ -171,6 +173,7 @@ error_fw_dnld_deinit:
error_free_dev:
nci_free_device(priv->ndev);
error_free:
+ gpiod_put(priv->config.reset_gpio);
kfree(priv);
return ERR_PTR(rc);
}
@@ -186,6 +189,8 @@ void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv)
nfcmrvl_fw_dnld_deinit(priv);
+ gpiod_put(priv->config.reset_gpio);
+
nci_free_device(ndev);
kfree(priv);
}
diff --git a/drivers/nfc/nfcmrvl/uart.c b/drivers/nfc/nfcmrvl/uart.c
index 9aedd168759c..3023757ab976 100644
--- a/drivers/nfc/nfcmrvl/uart.c
+++ b/drivers/nfc/nfcmrvl/uart.c
@@ -62,8 +62,7 @@ static const struct nfcmrvl_if_ops uart_ops = {
};
static int nfcmrvl_uart_parse_dt(struct device_node *node,
- struct nfcmrvl_platform_data *pdata,
- struct device *dev)
+ struct nfcmrvl_platform_data *pdata)
{
struct device_node *matched_node;
struct gpio_desc *reset_gpio;
@@ -86,11 +85,11 @@ static int nfcmrvl_uart_parse_dt(struct device_node *node,
pdata->flow_control = of_property_read_bool(matched_node, "flow-control");
pdata->break_control = of_property_read_bool(matched_node, "break-control");
- reset_gpio = devm_fwnode_gpiod_get_optional(dev,
- of_fwnode_handle(matched_node),
- "reset", GPIOD_OUT_HIGH,
- "nfcmrvl_reset_n");
- if (IS_ERR(reset_gpio)) {
+ reset_gpio = fwnode_gpiod_get(of_fwnode_handle(matched_node), "reset",
+ GPIOD_OUT_HIGH, "nfcmrvl_reset_n");
+ if (reset_gpio == ERR_PTR(-ENOENT)) {
+ reset_gpio = NULL;
+ } else if (IS_ERR(reset_gpio)) {
of_node_put(matched_node);
return PTR_ERR(reset_gpio);
}
@@ -119,7 +118,7 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu)
*/
if (dev && dev->parent && dev->parent->of_node)
- if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config, dev) == 0)
+ if (nfcmrvl_uart_parse_dt(dev->parent->of_node, &config) == 0)
pdata = &config;
if (!pdata) {
--
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