[PATCH 5.4 057/214] scsi: fcoe: Memory leak fix in fcoe_sysfs_fcf_del()

From
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date
2020-09-01 16:38:06
Also in
lkml
Reply to
Greg Kroah-Hartman, 2020-09-01
From: Javed Hasan <redacted>

[ Upstream commit e95b4789ff4380733006836d28e554dc296b2298 ]

In fcoe_sysfs_fcf_del(), we first deleted the fcf from the list and then
freed it if ctlr_dev was not NULL. This was causing a memory leak.

Free the fcf even if ctlr_dev is NULL.

Link: https://lore.kernel.org/r/20200729081824.30996-3-jhasan@marvell.com (local)
Reviewed-by: Girish Basrur <redacted>
Reviewed-by: Santosh Vernekar <redacted>
Reviewed-by: Saurav Kashyap <redacted>
Reviewed-by: Shyam Sundar <redacted>
Signed-off-by: Javed Hasan <redacted>
Signed-off-by: Martin K. Petersen <redacted>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/scsi/fcoe/fcoe_ctlr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/scsi/fcoe/fcoe_ctlr.c b/drivers/scsi/fcoe/fcoe_ctlr.c
index 1791a393795da..07a0dadc75bf5 100644
--- a/drivers/scsi/fcoe/fcoe_ctlr.c
+++ b/drivers/scsi/fcoe/fcoe_ctlr.c
@@ -255,9 +255,9 @@ static void fcoe_sysfs_fcf_del(struct fcoe_fcf *new)
 		WARN_ON(!fcf_dev);
 		new->fcf_dev = NULL;
 		fcoe_fcf_device_delete(fcf_dev);
-		kfree(new);
 		mutex_unlock(&cdev->lock);
 	}
+	kfree(new);
 }
 
 /**
-- 
2.25.1


Thread (219 messages) 219 messages, 4 authors, last reply 2020-09-02
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help