]> git.baikalelectronics.ru Git - kernel.git/commit
scsi: scsi_debug: Fix possible name leak in sdebug_add_host_helper()
authorYang Yingliang <yangyingliang@huawei.com>
Sat, 12 Nov 2022 13:10:10 +0000 (21:10 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:35 +0000 (13:32 +0100)
commit5bee8f57676a0b818dd34c7cb3af4ef91bca5ada
tree05dd091d0d63d43dd7d02b4fb0426e827256df6b
parentc901f8379a83064253f8485d306a9756f04791ae
scsi: scsi_debug: Fix possible name leak in sdebug_add_host_helper()

[ Upstream commit 9243c4f1bbe734c7355fe5ad8c5f35ff3ca1f7d9 ]

Afer commit 13e0419aca34 ("driver core: get rid of struct device's bus_id
string array"), the name of device is allocated dynamically, it needs be
freed when device_register() returns error.

As comment of device_register() says, one should use put_device() to give
up the reference in the error path. Fix this by calling put_device(), then
the name can be freed in kobject_cleanup(), and sdbg_host is freed in
sdebug_release_adapter().

When the device release is not set, it means the device is not initialized.
We can not call put_device() in this case. Use kfree() to free memory.

Fixes: 13e0419aca34 ("driver core: get rid of struct device's bus_id string array")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221112131010.3757845-1-yangyingliang@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/scsi/scsi_debug.c