diff mbox series

octeontx2-af: Fix memory leak of object buf

Message ID 20210323123245.346491-1-colin.king@canonical.com
State New
Headers show
Series octeontx2-af: Fix memory leak of object buf | expand

Commit Message

Colin King March 23, 2021, 12:32 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Currently the error return path when lfs fails to allocate is not free'ing
the memory allocated to buf. Fix this by adding the missing kfree.

Addresses-Coverity: ("Resource leak")
Fixes: f7884097141b ("octeontx2-af: Formatting debugfs entry rsrc_alloc.")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Sunil Kovvuri March 24, 2021, 7:07 a.m. UTC | #1
On Tue, Mar 23, 2021 at 6:07 PM Colin King <colin.king@canonical.com> wrote:
>
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently the error return path when lfs fails to allocate is not free'ing
> the memory allocated to buf. Fix this by adding the missing kfree.
>
> Addresses-Coverity: ("Resource leak")
> Fixes: f7884097141b ("octeontx2-af: Formatting debugfs entry rsrc_alloc.")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
> index 8ec17ee72b5d..9bf8eaabf9ab 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
> @@ -253,8 +253,10 @@ static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
>                 return -ENOSPC;
>
>         lfs = kzalloc(lf_str_size, GFP_KERNEL);
> -       if (!lfs)
> +       if (!lfs) {
> +               kfree(buf);
>                 return -ENOMEM;
> +       }
>         off +=  scnprintf(&buf[off], buf_size - 1 - off, "%-*s", lf_str_size,
>                           "pcifunc");
>         for (index = 0; index < BLK_COUNT; index++)
> --
> 2.30.2
>

Thanks for the fix,
Acked-by: Sunil Goutham <sgoutham@marvell.com>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
index 8ec17ee72b5d..9bf8eaabf9ab 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
@@ -253,8 +253,10 @@  static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
 		return -ENOSPC;
 
 	lfs = kzalloc(lf_str_size, GFP_KERNEL);
-	if (!lfs)
+	if (!lfs) {
+		kfree(buf);
 		return -ENOMEM;
+	}
 	off +=	scnprintf(&buf[off], buf_size - 1 - off, "%-*s", lf_str_size,
 			  "pcifunc");
 	for (index = 0; index < BLK_COUNT; index++)