* [PATCH] octeontx2-af: fix memory leak of lmac and lmac->name
@ 2021-01-07 12:39 Colin King
2021-01-07 17:01 ` Sunil Kovvuri
0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2021-01-07 12:39 UTC (permalink / raw)
To: Sunil Goutham, Linu Cherian, Geetha sowjanya, Jerin Jacob,
David S . Miller, Jakub Kicinski, Nithya Mani, netdev
Cc: kernel-janitors, linux-kernel
From: Colin Ian King <colin.king@canonical.com>
Currently the error return paths don't kfree lmac and lmac->name
leading to some memory leaks. Fix this by adding two error return
paths that kfree these objects
Addresses-Coverity: ("Resource leak")
Fixes: 1463f382f58d ("octeontx2-af: Add support for CGX link management")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
drivers/net/ethernet/marvell/octeontx2/af/cgx.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
index 1156c61f2e02..aa5da9691a1c 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/cgx.c
@@ -871,8 +871,10 @@ static int cgx_lmac_init(struct cgx *cgx)
if (!lmac)
return -ENOMEM;
lmac->name = kcalloc(1, sizeof("cgx_fwi_xxx_yyy"), GFP_KERNEL);
- if (!lmac->name)
- return -ENOMEM;
+ if (!lmac->name) {
+ err = -ENOMEM;
+ goto err_lmac_free;
+ }
sprintf(lmac->name, "cgx_fwi_%d_%d", cgx->cgx_id, i);
lmac->lmac_id = i;
lmac->cgx = cgx;
@@ -883,7 +885,7 @@ static int cgx_lmac_init(struct cgx *cgx)
CGX_LMAC_FWI + i * 9),
cgx_fwi_event_handler, 0, lmac->name, lmac);
if (err)
- return err;
+ goto err_irq;
/* Enable interrupt */
cgx_write(cgx, lmac->lmac_id, CGXX_CMRX_INT_ENA_W1S,
@@ -895,6 +897,12 @@ static int cgx_lmac_init(struct cgx *cgx)
}
return cgx_lmac_verify_fwi_version(cgx);
+
+err_irq:
+ kfree(lmac->name);
+err_lmac_free:
+ kfree(lmac);
+ return err;
}
static int cgx_lmac_exit(struct cgx *cgx)
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] octeontx2-af: fix memory leak of lmac and lmac->name
2021-01-07 12:39 [PATCH] octeontx2-af: fix memory leak of lmac and lmac->name Colin King
@ 2021-01-07 17:01 ` Sunil Kovvuri
2021-01-08 2:42 ` Jakub Kicinski
0 siblings, 1 reply; 3+ messages in thread
From: Sunil Kovvuri @ 2021-01-07 17:01 UTC (permalink / raw)
To: Colin King
Cc: Sunil Goutham, Linu Cherian, Geetha sowjanya, Jerin Jacob,
David S . Miller, Jakub Kicinski, Nithya Mani, Linux Netdev List,
kernel-janitors, LKML
On Thu, Jan 7, 2021 at 6:11 PM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently the error return paths don't kfree lmac and lmac->name
> leading to some memory leaks. Fix this by adding two error return
> paths that kfree these objects
>
> Addresses-Coverity: ("Resource leak")
> Fixes: 1463f382f58d ("octeontx2-af: Add support for CGX link management")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
Thanks for the fix, looks good to me.
Sunil.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] octeontx2-af: fix memory leak of lmac and lmac->name
2021-01-07 17:01 ` Sunil Kovvuri
@ 2021-01-08 2:42 ` Jakub Kicinski
0 siblings, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2021-01-08 2:42 UTC (permalink / raw)
To: Sunil Kovvuri
Cc: Colin King, Sunil Goutham, Linu Cherian, Geetha sowjanya,
Jerin Jacob, David S . Miller, Nithya Mani, Linux Netdev List,
kernel-janitors, LKML
On Thu, 7 Jan 2021 22:31:30 +0530 Sunil Kovvuri wrote:
> On Thu, Jan 7, 2021 at 6:11 PM Colin King <colin.king@canonical.com> wrote:
> >
> > From: Colin Ian King <colin.king@canonical.com>
> >
> > Currently the error return paths don't kfree lmac and lmac->name
> > leading to some memory leaks. Fix this by adding two error return
> > paths that kfree these objects
> >
> > Addresses-Coverity: ("Resource leak")
> > Fixes: 1463f382f58d ("octeontx2-af: Add support for CGX link management")
> > Signed-off-by: Colin Ian King <colin.king@canonical.com>
>
> Thanks for the fix, looks good to me.
Consider venturing an Acked-by tag in the future so it can be recorded
in git.
Applied, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-01-08 2:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-07 12:39 [PATCH] octeontx2-af: fix memory leak of lmac and lmac->name Colin King
2021-01-07 17:01 ` Sunil Kovvuri
2021-01-08 2:42 ` Jakub Kicinski
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).