From: YueHaibing <yuehaibing@huawei.com>
To: <martin.petersen@oracle.com>, <jejb@linux.ibm.com>,
<hare@suse.de>, <sedat.dilek@gmail.com>, <jth@kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <linux-scsi@vger.kernel.org>,
YueHaibing <yuehaibing@huawei.com>
Subject: [PATCH] scsi: fcoe: Fix possible memleak in fcoe_if_init
Date: Mon, 3 Jun 2019 17:22:18 +0800 [thread overview]
Message-ID: <20190603092218.15064-1-yuehaibing@huawei.com> (raw)
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
reply other threads:[~2019-06-03 9:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190603092218.15064-1-yuehaibing@huawei.com \
--to=yuehaibing@huawei.com \
--cc=hare@suse.de \
--cc=jejb@linux.ibm.com \
--cc=jth@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=sedat.dilek@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).