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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
Cc: Sesidhar Baddela <sebaddel@xxxxxxxxx>
Cc: "James E.J. Bottomley" <jejb@xxxxxxxxxxxxx>
Cc: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx>
Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
---
 drivers/scsi/snic/snic_disc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

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));
-- 
2.25.1




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux