cxgb4: fix a memory leak bug [Linux 4.9.192]

This Linux kernel change "cxgb4: fix a memory leak bug" is included in the Linux 4.9.192 release. This change is authored by Wenwen Wang <wenwen [at]> on Tue Aug 13 04:18:52 2019 -0500. The commit for this change in Linux stable tree is 0b9e625 (patch) which is from upstream commit c554336. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream c554336.

cxgb4: fix a memory leak bug

[ Upstream commit c554336efa9bbc28d6ec14efbee3c7d63c61a34f ]

In blocked_fl_write(), 't' is not deallocated if bitmap_parse_user() fails,
leading to a memory leak bug. To fix this issue, free t before returning
the error.

Signed-off-by: Wenwen Wang <>
Signed-off-by: David S. Miller <>
Signed-off-by: Sasha Levin <>

There are 4 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
index 20455d0..61c5562 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c
@@ -2781,8 +2781,10 @@ static ssize_t blocked_fl_write(struct file *filp, const char __user *ubuf,
        return -ENOMEM;

    err = bitmap_parse_user(ubuf, count, t, adap->sge.egr_sz);
-   if (err)
+   if (err) {
+       kvfree(t);
        return err;
+   }

    bitmap_copy(adap->sge.blocked_fl, t, adap->sge.egr_sz);

Leave a Reply

Your email address will not be published. Required fields are marked *