All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Yingliang <yangyingliang@huawei.com>
To: <open-iscsi@googlegroups.com>, <linux-scsi@vger.kernel.org>
Cc: <lduncan@suse.com>, <cleech@redhat.com>,
	<michael.christie@oracle.com>, <jejb@linux.ibm.com>,
	<martin.petersen@oracle.com>, <yangyingliang@huawei.com>
Subject: [PATCH] scsi: iscsi: fix possible memory leak when transport_register_device() fails
Date: Wed, 9 Nov 2022 17:24:21 +0800	[thread overview]
Message-ID: <20221109092421.3111613-1-yangyingliang@huawei.com> (raw)

If transport_register_device() fails, transport_destroy_device() should
be called to release the memory allocated in transport_setup_device().

Fixes: 0896b7523026 ("[SCSI] open-iscsi/linux-iscsi-5 Initiator: Transport class update for iSCSI")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/scsi/scsi_transport_iscsi.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index cd3db9684e52..88add31a56e3 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -2085,6 +2085,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
 	return 0;
 
 release_dev:
+	transport_destroy_device(&session->dev);
 	device_del(&session->dev);
 release_ida:
 	if (session->ida_used)
@@ -2462,6 +2463,7 @@ int iscsi_add_conn(struct iscsi_cls_conn *conn)
 	if (err) {
 		iscsi_cls_session_printk(KERN_ERR, session,
 					 "could not register transport's dev\n");
+		transport_destroy_device(&conn->dev);
 		device_del(&conn->dev);
 		return err;
 	}
-- 
2.25.1


             reply	other threads:[~2022-11-09  9:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09  9:24 Yang Yingliang [this message]
2022-11-09 18:51 ` [PATCH] scsi: iscsi: fix possible memory leak when transport_register_device() fails Mike Christie
2022-11-10  1:31   ` Yang Yingliang

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=20221109092421.3111613-1-yangyingliang@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=cleech@redhat.com \
    --cc=jejb@linux.ibm.com \
    --cc=lduncan@suse.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=michael.christie@oracle.com \
    --cc=open-iscsi@googlegroups.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.