Skip to content

Commit 7723a5d

Browse files
PeterZhu789gregkh
authored andcommitted
scsi: snic: Fix possible memory leak if device_add() fails
commit 41320b1 upstream. If device_add() returns error, the name allocated by dev_set_name() needs be freed. As the comment of device_add() says, put_device() should be used to give up the reference in the error path. So fix this by calling put_device(), then the name can be freed in kobject_cleanp(). Fixes: c8806b6 ("snic: driver for Cisco SCSI HBA") Signed-off-by: Zhu Wang <wangzhu9@huawei.com> Acked-by: Narsimhulu Musini <nmusini@cisco.com> Link: https://lore.kernel.org/r/20230801111421.63651-1-wangzhu9@huawei.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9fdb273 commit 7723a5d

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/scsi/snic/snic_disc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ snic_tgt_create(struct snic *snic, struct snic_tgt_id *tgtid)
303303
"Snic Tgt: device_add, with err = %d\n",
304304
ret);
305305

306+
put_device(&tgt->dev);
306307
put_device(&snic->shost->shost_gendev);
307308
spin_lock_irqsave(snic->shost->host_lock, flags);
308309
list_del(&tgt->list);

0 commit comments

Comments
 (0)