[PATCH net v3 0/3] net: liquidio: Fix memory leaks in setup_nic_devices()

Zilin Guan posted 3 patches 1 week, 3 days ago
There is a newer version of this series
.../net/ethernet/cavium/liquidio/lio_main.c   | 38 ++++++++++---------
.../ethernet/cavium/liquidio/lio_vf_main.c    |  3 +-
2 files changed, 22 insertions(+), 19 deletions(-)
[PATCH net v3 0/3] net: liquidio: Fix memory leaks in setup_nic_devices()
Posted by Zilin Guan 1 week, 3 days ago
This series fixes memory leaks in the initialization paths of the 
NIC devices.

Patch 1 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 2 fixes the same off-by-one error in the VF cleanup loop.

Patch 3 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.

Signed-off-by: Zilin Guan <zilin@seu.edu.cn>

Changes in v3:
- Split the off-by-one fix into separate patches for PF and VF.
- Patch 1: Decrement i in the devlink_alloc error path before jumping
  to cleanup to avoid accessing an invalid index.
- Patch 3: Initialize lio->oct_dev alongside props->netdev to prevent 
  NULL pointer dereference in cleanup_rx_oom_poll_fn().

Changes in v2:
- Add patch 1 to fix an off-by-one error in the error handling loop logic.

Zilin Guan (3):
  net: liquidio: Fix off-by-one error in PF setup_nic_devices() cleanup
  net: liquidio: Fix off-by-one error in VF setup_nic_devices() cleanup
  net: liquidio: Initialize netdev pointer before queue setup

 .../net/ethernet/cavium/liquidio/lio_main.c   | 38 ++++++++++---------
 .../ethernet/cavium/liquidio/lio_vf_main.c    |  3 +-
 2 files changed, 22 insertions(+), 19 deletions(-)

-- 
2.34.1
Re: [PATCH net v3 0/3] net: liquidio: Fix memory leaks in setup_nic_devices()
Posted by Jakub Kicinski 1 week, 3 days ago
On Tue, 27 Jan 2026 15:12:38 +0000 Zilin Guan wrote:
> This series fixes memory leaks in the initialization paths of the 
> NIC devices.
> 
> Patch 1 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 2 fixes the same off-by-one error in the VF cleanup loop.
> 
> Patch 3 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.

Coccicheck says:

drivers/net/ethernet/cavium/liquidio/lio_main.c:3769:8-9: WARNING: Unsigned expression compared with zero: i >= 0
drivers/net/ethernet/cavium/liquidio/lio_vf_main.c:2215:8-9: WARNING: Unsigned expression compared with zero: i >= 0
-- 
pw-bot: cr
Re: [PATCH net v3 0/3] net: liquidio: Fix memory leaks in setup_nic_devices()
Posted by Zilin Guan 1 week, 3 days ago
On Tue, Jan 27, 2026 at 01:05:46PM -0800, Jakub Kicinski wrote:
> On Tue, 27 Jan 2026 15:12:38 +0000 Zilin Guan wrote:
> > This series fixes memory leaks in the initialization paths of the 
> > NIC devices.
> > 
> > Patch 1 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 2 fixes the same off-by-one error in the VF cleanup loop.
> > 
> > Patch 3 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.
> 
> Coccicheck says:
> 
> drivers/net/ethernet/cavium/liquidio/lio_main.c:3769:8-9: WARNING: Unsigned expression compared with zero: i >= 0
> drivers/net/ethernet/cavium/liquidio/lio_vf_main.c:2215:8-9: WARNING: Unsigned expression compared with zero: i >= 0
> -- 
> pw-bot: cr

Apologies for missing the unsigned integer issue here. I was worried 
about a potential underflow during the devlink_alloc failure path if 
the loop hadn't run, which led to the while (i >= 0) approach. I'll 
fix this in v4. Thanks for catching that!

Regards,
Zilin