Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-liquidio-fix-memory-leaks-in-setup_nic_devices'

Zilin Guan says:

====================
net: liquidio: Fix memory leaks in setup_nic_devices()

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.
====================

Link: https://patch.msgid.link/20260128154440.278369-1-zilin@seu.edu.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+22 -21
+20 -19
drivers/net/ethernet/cavium/liquidio/lio_main.c
··· 3505 3505 */ 3506 3506 netdev->netdev_ops = &lionetdevops; 3507 3507 3508 + lio = GET_LIO(netdev); 3509 + 3510 + memset(lio, 0, sizeof(struct lio)); 3511 + 3512 + lio->ifidx = ifidx_or_pfnum; 3513 + 3514 + props = &octeon_dev->props[i]; 3515 + props->gmxport = resp->cfg_info.linfo.gmxport; 3516 + props->netdev = netdev; 3517 + 3518 + /* Point to the properties for octeon device to which this 3519 + * interface belongs. 3520 + */ 3521 + lio->oct_dev = octeon_dev; 3522 + lio->octprops = props; 3523 + lio->netdev = netdev; 3524 + 3508 3525 retval = netif_set_real_num_rx_queues(netdev, num_oqueues); 3509 3526 if (retval) { 3510 3527 dev_err(&octeon_dev->pci_dev->dev, ··· 3537 3520 WRITE_ONCE(sc->caller_is_done, true); 3538 3521 goto setup_nic_dev_free; 3539 3522 } 3540 - 3541 - lio = GET_LIO(netdev); 3542 - 3543 - memset(lio, 0, sizeof(struct lio)); 3544 - 3545 - lio->ifidx = ifidx_or_pfnum; 3546 - 3547 - props = &octeon_dev->props[i]; 3548 - props->gmxport = resp->cfg_info.linfo.gmxport; 3549 - props->netdev = netdev; 3550 3523 3551 3524 lio->linfo.num_rxpciq = num_oqueues; 3552 3525 lio->linfo.num_txpciq = num_iqueues; ··· 3602 3595 /* MTU range: 68 - 16000 */ 3603 3596 netdev->min_mtu = LIO_MIN_MTU_SIZE; 3604 3597 netdev->max_mtu = LIO_MAX_MTU_SIZE; 3605 - 3606 - /* Point to the properties for octeon device to which this 3607 - * interface belongs. 3608 - */ 3609 - lio->oct_dev = octeon_dev; 3610 - lio->octprops = props; 3611 - lio->netdev = netdev; 3612 3598 3613 3599 dev_dbg(&octeon_dev->pci_dev->dev, 3614 3600 "if%d gmx: %d hw_addr: 0x%llx\n", i, ··· 3750 3750 if (!devlink) { 3751 3751 device_unlock(&octeon_dev->pci_dev->dev); 3752 3752 dev_err(&octeon_dev->pci_dev->dev, "devlink alloc failed\n"); 3753 + i--; 3753 3754 goto setup_nic_dev_free; 3754 3755 } 3755 3756 ··· 3766 3765 3767 3766 setup_nic_dev_free: 3768 3767 3769 - while (i--) { 3768 + do { 3770 3769 dev_err(&octeon_dev->pci_dev->dev, 3771 3770 "NIC ifidx:%d Setup failed\n", i); 3772 3771 liquidio_destroy_nic_device(octeon_dev, i); 3773 - } 3772 + } while (i--); 3774 3773 3775 3774 setup_nic_dev_done: 3776 3775
+2 -2
drivers/net/ethernet/cavium/liquidio/lio_vf_main.c
··· 2212 2212 2213 2213 setup_nic_dev_free: 2214 2214 2215 - while (i--) { 2215 + do { 2216 2216 dev_err(&octeon_dev->pci_dev->dev, 2217 2217 "NIC ifidx:%d Setup failed\n", i); 2218 2218 liquidio_destroy_nic_device(octeon_dev, i); 2219 - } 2219 + } while (i--); 2220 2220 2221 2221 setup_nic_dev_done: 2222 2222