lkml.org 
[lkml]   [2019]   [Jun]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] scsi: fcoe: Fix possible memleak in fcoe_if_init
Date
If it fails to alloc fcoe_vport_scsi_transport in fcoe_if_init,
we should check the err and free allocted fcoe_nport_scsi_transport.
Also return ENOMEM instead of ENODEV.

Fixes: 8ca86f84dd5f ("[SCSI] fcoe: prepare fcoe for using fcoe transport")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
---
drivers/scsi/fcoe/fcoe.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 8ba8862..12ca0b7 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -1262,12 +1262,17 @@ static int __init fcoe_if_init(void)
/* attach to scsi transport */
fcoe_nport_scsi_transport =
fc_attach_transport(&fcoe_nport_fc_functions);
+ if (!fcoe_nport_scsi_transport)
+ return -ENOMEM;
+
fcoe_vport_scsi_transport =
fc_attach_transport(&fcoe_vport_fc_functions);

- if (!fcoe_nport_scsi_transport) {
- printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
- return -ENODEV;
+ if (!fcoe_vport_scsi_transport) {
+ pr_err("fcoe: Failed to attach to the FC transport\n");
+ fc_release_transport(fcoe_nport_scsi_transport);
+ fcoe_nport_scsi_transport = NULL;
+ return -ENOMEM;
}

return 0;
--
1.8.3.1

\
 
 \ /
  Last update: 2019-06-03 11:24    [W:2.456 / U:0.260 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site