Re: [PATCH net] net: liquidio: Fix memory leak in setup_nic_devices()
From: Zilin Guan
Date: Sat Jan 24 2026 - 02:21:33 EST
On Fri, Jan 23, 2026 at 05:21:11PM +0000, Simon Horman wrote:
> Thanks Zilin,
>
> I agree with your analysis, and proposed fix.
> And that the problem appears to have been introduced in the cited commit.
>
> But I am wondering if we also need the following, probably as a separate
> commit, to ensure that liquidio_destroy_nic_device is called for the
> element of props[i] whose assingment your patch addresses.
>
> Also compile tested only.
>
> diff --git a/drivers/net/ethernet/cavium/liquidio/lio_main.c b/drivers/net/ethernet/cavium/liquidio/lio_main.c
> index 0732440eeacd..3ba2806f5d1e 100644
> --- a/drivers/net/ethernet/cavium/liquidio/lio_main.c
> +++ b/drivers/net/ethernet/cavium/liquidio/lio_main.c
> @@ -3765,11 +3765,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:
>
> ...
Hi Simon,
Thanks for the review and the suggestion.
I agree with you. The current while (i--) loop indeed skips the cleanup
for the device index i that actually failed. I also noticed that
lio_vf_main.c shares the exact same issues.
I'll send a v2 series to correct both files, and I'll include the loop fix
as a separate commit as you suggested.
Best regards,
Zilin