ionic: fix memory leak of object 'lid'

Currently when netdev fails to allocate the error return path
fails to free the allocated object 'lid'.  Fix this by setting
err to the return error code and jumping to a new label that
performs the kfree of lid before returning.

Addresses-Coverity: ("Resource leak")
Fixes: 4b03b27349 ("ionic: get MTU from lif identity")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Acked-by: Shannon Nelson <snelson@pensando.io>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Colin Ian King 2020-07-22 18:40:03 +01:00 committed by David S. Miller
parent aff598caed
commit 4b1debbe63

View File

@ -2037,7 +2037,8 @@ static struct ionic_lif *ionic_lif_alloc(struct ionic *ionic, unsigned int index
ionic->ntxqs_per_lif, ionic->ntxqs_per_lif);
if (!netdev) {
dev_err(dev, "Cannot allocate netdev, aborting\n");
return ERR_PTR(-ENOMEM);
err = -ENOMEM;
goto err_out_free_lid;
}
SET_NETDEV_DEV(netdev, dev);
@ -2123,6 +2124,7 @@ err_out_free_lif_info:
err_out_free_netdev:
free_netdev(lif->netdev);
lif = NULL;
err_out_free_lid:
kfree(lid);
return ERR_PTR(err);