diff mbox series

[1/2] scsi: snic: fix possible memory leak in snic_tgt_create()

Message ID 20221103125938.124819-2-yangyingliang@huawei.com (mailing list archive)
State Deferred
Headers show
Series scsi: snic: fixes two source leaks | expand

Commit Message

Yang Yingliang Nov. 3, 2022, 12:59 p.m. UTC
The device name allocated by dev_set_name() in snic_tgt_create() needs be
freed if device_add(&tgt->dev) returns error, as comment of device_add()
says, it should call put_device() to drop the reference on error.

Fix it by calling put_device(&rc->dev), so that the name can be freed in
kobject_cleanup(). The 'tgt' is freed in snic_tgt_dev_release(), so kfree()
in error path can be removed.

Fixes: c8806b6c9e82 ("snic: driver for Cisco SCSI HBA")
Cc: Karan Tilak Kumar <kartilak@cisco.com>
Cc: Sesidhar Baddela <sebaddel@cisco.com>
Cc: "James E.J. Bottomley" <jejb@linux.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 drivers/scsi/snic/snic_disc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/scsi/snic/snic_disc.c b/drivers/scsi/snic/snic_disc.c
index 9b2b5f8c23b9..031c27d8510f 100644
--- a/drivers/scsi/snic/snic_disc.c
+++ b/drivers/scsi/snic/snic_disc.c
@@ -304,10 +304,8 @@  snic_tgt_create(struct snic *snic, struct snic_tgt_id *tgtid)
 			      ret);
 
 		put_device(&snic->shost->shost_gendev);
-		kfree(tgt);
-		tgt = NULL;
-
-		return tgt;
+		put_device(&tgt->dev);
+		return NULL;
 	}
 
 	SNIC_HOST_INFO(snic->shost, "Scanning %s.\n", dev_name(&tgt->dev));