* [PATCH][next] ionic: fix memory leak of object 'lid'
@ 2020-07-22 17:40 Colin King
2020-07-22 21:18 ` Shannon Nelson
2020-07-23 1:10 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2020-07-22 17:40 UTC (permalink / raw)
To: Shannon Nelson, Pensando Drivers, David S . Miller,
Jakub Kicinski, netdev
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
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: 4b03b27349c0 ("ionic: get MTU from lif identity")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/net/ethernet/pensando/ionic/ionic_lif.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
index 7ad338a4653c..728dd6429d80 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
@@ -2034,7 +2034,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);
@@ -2120,6 +2121,7 @@ static struct ionic_lif *ionic_lif_alloc(struct ionic *ionic, unsigned int index
err_out_free_netdev:
free_netdev(lif->netdev);
lif = NULL;
+err_out_free_lid:
kfree(lid);
return ERR_PTR(err);
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH][next] ionic: fix memory leak of object 'lid'
2020-07-22 17:40 [PATCH][next] ionic: fix memory leak of object 'lid' Colin King
@ 2020-07-22 21:18 ` Shannon Nelson
2020-07-23 1:10 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Shannon Nelson @ 2020-07-22 21:18 UTC (permalink / raw)
To: Colin King, Pensando Drivers, David S . Miller, Jakub Kicinski,
netdev
Cc: kernel-janitors, linux-kernel
On 7/22/20 10:40 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 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: 4b03b27349c0 ("ionic: get MTU from lif identity")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
> drivers/net/ethernet/pensando/ionic/ionic_lif.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_lif.c b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> index 7ad338a4653c..728dd6429d80 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_lif.c
> @@ -2034,7 +2034,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);
> @@ -2120,6 +2121,7 @@ static struct ionic_lif *ionic_lif_alloc(struct ionic *ionic, unsigned int index
> err_out_free_netdev:
> free_netdev(lif->netdev);
> lif = NULL;
> +err_out_free_lid:
> kfree(lid);
>
> return ERR_PTR(err);
Thanks!
Acked-by: Shannon Nelson <snelson@pensando.io>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][next] ionic: fix memory leak of object 'lid'
2020-07-22 17:40 [PATCH][next] ionic: fix memory leak of object 'lid' Colin King
2020-07-22 21:18 ` Shannon Nelson
@ 2020-07-23 1:10 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2020-07-23 1:10 UTC (permalink / raw)
To: colin.king; +Cc: snelson, drivers, kuba, netdev, kernel-janitors, linux-kernel
From: Colin King <colin.king@canonical.com>
Date: Wed, 22 Jul 2020 18:40:03 +0100
> From: Colin Ian King <colin.king@canonical.com>
>
> 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: 4b03b27349c0 ("ionic: get MTU from lif identity")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-07-23 1:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-22 17:40 [PATCH][next] ionic: fix memory leak of object 'lid' Colin King
2020-07-22 21:18 ` Shannon Nelson
2020-07-23 1:10 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).