octeontx2-af: Fix memory leak of object buf
authorColin Ian King <colin.king@canonical.com>
Tue, 23 Mar 2021 12:32:45 +0000 (12:32 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 24 Mar 2021 19:33:06 +0000 (12:33 -0700)
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>
Acked-by: Sunil Goutham <sgoutham@marvell.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c

index b4c53b19f5350d15872fcb63663bf35d9f396de7..de3968d2e5ce72aa9e492fe61537bbec038296d4 100644 (file)
@@ -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++)