mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-04-02 09:21:19 -04:00
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>
This commit is contained in:
@@ -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));
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user