scsi: iscsi: Fix possible memory leak when device_register() failed
authorZhou Guanghui <zhouguanghui1@huawei.com>
Thu, 10 Nov 2022 03:37:29 +0000 (03:37 +0000)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 17 Nov 2022 17:53:36 +0000 (17:53 +0000)
commitf014165faa7b953b81dcbf18835936e5f8d01f2a
tree74029e4d37d7153f843bfeafafc4fe762d1ad49d
parent0954256e970ecf371b03a6c9af2cf91b9c4085ff
scsi: iscsi: Fix possible memory leak when device_register() failed

If device_register() returns error, the name allocated by the
dev_set_name() need be freed. As described in the comment of
device_register(), we should use put_device() to give up the reference in
the error path.

Fix this by calling put_device(), the name will be freed in the
kobject_cleanup(), and this patch modified resources will be released by
calling the corresponding callback function in the device_release().

Signed-off-by: Zhou Guanghui <zhouguanghui1@huawei.com>
Link: https://lore.kernel.org/r/20221110033729.1555-1-zhouguanghui1@huawei.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/scsi_transport_iscsi.c