* [PATCH net v4 1/3] net: liquidio: Initialize netdev pointer before queue setup
2026-01-28 15:44 [PATCH net v4 0/3] net: liquidio: Fix memory leaks in setup_nic_devices() Zilin Guan
@ 2026-01-28 15:44 ` Zilin Guan
2026-01-28 15:44 ` [PATCH net v4 2/3] net: liquidio: Fix off-by-one error in PF setup_nic_devices() cleanup Zilin Guan
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Zilin Guan @ 2026-01-28 15:44 UTC (permalink / raw)
To: andrew+netdev
Cc: davem, edumazet, kuba, pabeni, netdev, linux-kernel,
kory.maincent, horms, jianhao.xu, marco.crivellari,
vadim.fedorenko, Zilin Guan
In setup_nic_devices(), the netdev is allocated using alloc_etherdev_mq().
However, the pointer to this structure is stored in oct->props[i].netdev
only after the calls to netif_set_real_num_rx_queues() and
netif_set_real_num_tx_queues().
If either of these functions fails, setup_nic_devices() returns an error
without freeing the allocated netdev. Since oct->props[i].netdev is still
NULL at this point, the cleanup function liquidio_destroy_nic_device()
will fail to find and free the netdev, resulting in a memory leak.
Fix this by initializing oct->props[i].netdev before calling the queue
setup functions. This ensures that the netdev is properly accessible for
cleanup in case of errors.
Compile tested only. Issue found using a prototype static analysis tool
and code review.
Fixes: c33c997346c3 ("liquidio: enhanced ethtool --set-channels feature")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
.../net/ethernet/cavium/liquidio/lio_main.c | 34 +++++++++----------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/ethernet/cavium/liquidio/lio_main.c
index 0732440eeacd..1f10b1b22a1e 100644
--- a/drivers/net/ethernet/cavium/liquidio/lio_main.c
+++ b/drivers/net/ethernet/cavium/liquidio/lio_main.c
@@ -3505,6 +3505,23 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
*/
netdev->netdev_ops = &lionetdevops;
+ lio = GET_LIO(netdev);
+
+ memset(lio, 0, sizeof(struct lio));
+
+ lio->ifidx = ifidx_or_pfnum;
+
+ props = &octeon_dev->props[i];
+ props->gmxport = resp->cfg_info.linfo.gmxport;
+ props->netdev = netdev;
+
+ /* Point to the properties for octeon device to which this
+ * interface belongs.
+ */
+ lio->oct_dev = octeon_dev;
+ lio->octprops = props;
+ lio->netdev = netdev;
+
retval = netif_set_real_num_rx_queues(netdev, num_oqueues);
if (retval) {
dev_err(&octeon_dev->pci_dev->dev,
@@ -3521,16 +3538,6 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
goto setup_nic_dev_free;
}
- lio = GET_LIO(netdev);
-
- memset(lio, 0, sizeof(struct lio));
-
- lio->ifidx = ifidx_or_pfnum;
-
- props = &octeon_dev->props[i];
- props->gmxport = resp->cfg_info.linfo.gmxport;
- props->netdev = netdev;
-
lio->linfo.num_rxpciq = num_oqueues;
lio->linfo.num_txpciq = num_iqueues;
for (j = 0; j < num_oqueues; j++) {
@@ -3596,13 +3603,6 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
netdev->min_mtu = LIO_MIN_MTU_SIZE;
netdev->max_mtu = LIO_MAX_MTU_SIZE;
- /* Point to the properties for octeon device to which this
- * interface belongs.
- */
- lio->oct_dev = octeon_dev;
- lio->octprops = props;
- lio->netdev = netdev;
-
dev_dbg(&octeon_dev->pci_dev->dev,
"if%d gmx: %d hw_addr: 0x%llx\n", i,
lio->linfo.gmxport, CVM_CAST64(lio->linfo.hw_addr));
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net v4 2/3] net: liquidio: Fix off-by-one error in PF setup_nic_devices() cleanup
2026-01-28 15:44 [PATCH net v4 0/3] net: liquidio: Fix memory leaks in setup_nic_devices() Zilin Guan
2026-01-28 15:44 ` [PATCH net v4 1/3] net: liquidio: Initialize netdev pointer before queue setup Zilin Guan
@ 2026-01-28 15:44 ` Zilin Guan
2026-01-28 15:44 ` [PATCH net v4 3/3] net: liquidio: Fix off-by-one error in VF " Zilin Guan
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Zilin Guan @ 2026-01-28 15:44 UTC (permalink / raw)
To: andrew+netdev
Cc: davem, edumazet, kuba, pabeni, netdev, linux-kernel,
kory.maincent, horms, jianhao.xu, marco.crivellari,
vadim.fedorenko, Zilin Guan
In setup_nic_devices(), the initialization loop jumps to the label
setup_nic_dev_free on failure. The current cleanup loop while(i--)
skip the failing index i, causing a memory leak.
Fix this by changing the loop to iterate from the current index i
down to 0.
Also, decrement i in the devlink_alloc failure path to point to the
last successfully allocated index.
Compile tested only. Issue found using code review.
Fixes: f21fb3ed364b ("Add support of Cavium Liquidio ethernet adapters")
Suggested-by: Simon Horman <horms@kernel.org>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
drivers/net/ethernet/cavium/liquidio/lio_main.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/ethernet/cavium/liquidio/lio_main.c
index 1f10b1b22a1e..c1a3df225254 100644
--- a/drivers/net/ethernet/cavium/liquidio/lio_main.c
+++ b/drivers/net/ethernet/cavium/liquidio/lio_main.c
@@ -3750,6 +3750,7 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
if (!devlink) {
device_unlock(&octeon_dev->pci_dev->dev);
dev_err(&octeon_dev->pci_dev->dev, "devlink alloc failed\n");
+ i--;
goto setup_nic_dev_free;
}
@@ -3765,11 +3766,11 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
setup_nic_dev_free:
- while (i--) {
+ do {
dev_err(&octeon_dev->pci_dev->dev,
"NIC ifidx:%d Setup failed\n", i);
liquidio_destroy_nic_device(octeon_dev, i);
- }
+ } while (i--);
setup_nic_dev_done:
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net v4 3/3] net: liquidio: Fix off-by-one error in VF setup_nic_devices() cleanup
2026-01-28 15:44 [PATCH net v4 0/3] net: liquidio: Fix memory leaks in setup_nic_devices() Zilin Guan
2026-01-28 15:44 ` [PATCH net v4 1/3] net: liquidio: Initialize netdev pointer before queue setup Zilin Guan
2026-01-28 15:44 ` [PATCH net v4 2/3] net: liquidio: Fix off-by-one error in PF setup_nic_devices() cleanup Zilin Guan
@ 2026-01-28 15:44 ` Zilin Guan
2026-01-28 15:54 ` [PATCH net v4 0/3] net: liquidio: Fix memory leaks in setup_nic_devices() Kory Maincent
2026-01-30 3:40 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 6+ messages in thread
From: Zilin Guan @ 2026-01-28 15:44 UTC (permalink / raw)
To: andrew+netdev
Cc: davem, edumazet, kuba, pabeni, netdev, linux-kernel,
kory.maincent, horms, jianhao.xu, marco.crivellari,
vadim.fedorenko, Zilin Guan
In setup_nic_devices(), the initialization loop jumps to the label
setup_nic_dev_free on failure. The current cleanup loop while(i--)
skip the failing index i, causing a memory leak.
Fix this by changing the loop to iterate from the current index i
down to 0.
Compile tested only. Issue found using code review.
Fixes: 846b46873eeb ("liquidio CN23XX: VF offload features")
Suggested-by: Simon Horman <horms@kernel.org>
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
drivers/net/ethernet/cavium/liquidio/lio_vf_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
index e02942dbbcce..43c595f3b84e 100644
--- a/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
+++ b/drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
@@ -2212,11 +2212,11 @@ static int setup_nic_devices(struct octeon_device *octeon_dev)
setup_nic_dev_free:
- while (i--) {
+ do {
dev_err(&octeon_dev->pci_dev->dev,
"NIC ifidx:%d Setup failed\n", i);
liquidio_destroy_nic_device(octeon_dev, i);
- }
+ } while (i--);
setup_nic_dev_done:
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH net v4 0/3] net: liquidio: Fix memory leaks in setup_nic_devices()
2026-01-28 15:44 [PATCH net v4 0/3] net: liquidio: Fix memory leaks in setup_nic_devices() Zilin Guan
` (2 preceding siblings ...)
2026-01-28 15:44 ` [PATCH net v4 3/3] net: liquidio: Fix off-by-one error in VF " Zilin Guan
@ 2026-01-28 15:54 ` Kory Maincent
2026-01-30 3:40 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 6+ messages in thread
From: Kory Maincent @ 2026-01-28 15:54 UTC (permalink / raw)
To: Zilin Guan
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, horms, jianhao.xu, marco.crivellari,
vadim.fedorenko
On Wed, 28 Jan 2026 15:44:37 +0000
Zilin Guan <zilin@seu.edu.cn> wrote:
> This series fixes memory leaks in the initialization paths of the
> NIC devices.
>
> Patch 1 moves the initialization of oct->props[i].netdev before queue
> setup calls. This ensures that if queue setup fails, the cleanup function
> can find and free the allocated netdev. It also initializes lio->oct_dev
> early to prevent a crash in the cleanup path.
>
> Patch 2 fixes an off-by-one error in the PF cleanup loop. It ensures
> the current device index is cleaned up and correctly handles the
> post-loop devlink_alloc failure case.
>
> Patch 3 fixes the same off-by-one error in the VF cleanup loop.
For the series:
Reviewed-by: Kory Maincent <kory.maincent@bootlin.com>
Thank you!
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH net v4 0/3] net: liquidio: Fix memory leaks in setup_nic_devices()
2026-01-28 15:44 [PATCH net v4 0/3] net: liquidio: Fix memory leaks in setup_nic_devices() Zilin Guan
` (3 preceding siblings ...)
2026-01-28 15:54 ` [PATCH net v4 0/3] net: liquidio: Fix memory leaks in setup_nic_devices() Kory Maincent
@ 2026-01-30 3:40 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-01-30 3:40 UTC (permalink / raw)
To: Zilin Guan
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, kory.maincent, horms, jianhao.xu, marco.crivellari,
vadim.fedorenko
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 28 Jan 2026 15:44:37 +0000 you wrote:
> This series fixes memory leaks in the initialization paths of the
> NIC devices.
>
> Patch 1 moves the initialization of oct->props[i].netdev before queue
> setup calls. This ensures that if queue setup fails, the cleanup function
> can find and free the allocated netdev. It also initializes lio->oct_dev
> early to prevent a crash in the cleanup path.
>
> [...]
Here is the summary with links:
- [net,v4,1/3] net: liquidio: Initialize netdev pointer before queue setup
https://git.kernel.org/netdev/net/c/926ede0c85e1
- [net,v4,2/3] net: liquidio: Fix off-by-one error in PF setup_nic_devices() cleanup
https://git.kernel.org/netdev/net/c/8558aef4e8a1
- [net,v4,3/3] net: liquidio: Fix off-by-one error in VF setup_nic_devices() cleanup
https://git.kernel.org/netdev/net/c/6cbba46934ae
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread