]> git.baikalelectronics.ru Git - kernel.git/commit
scsi: fcoe: Fix possible name leak when device_register() fails
authorYang Yingliang <yangyingliang@huawei.com>
Sat, 12 Nov 2022 09:43:10 +0000 (17:43 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:19 +0000 (11:41 +0100)
commit41bdc85e9a60157a69186b3d0a37d63150290113
tree9f1a9cb7a82c1031c9e7d0055989d0277fc7a100
parentd4002cbabe05a4fc813f604e15dd72440fbdf566
scsi: fcoe: Fix possible name leak when device_register() fails

[ Upstream commit 47b6a122c7b69a876c7ee2fc064a26b09627de9d ]

If device_register() returns an error, the name allocated by dev_set_name()
needs to be freed. As the 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().

The 'fcf' is freed in fcoe_fcf_device_release(), so the kfree() in the
error path can be removed.

The 'ctlr' is freed in fcoe_ctlr_device_release(), so don't use the error
label, just return NULL after calling put_device().

Fixes: 679bdc185b60 ("[SCSI] libfcoe: Add fcoe_sysfs")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Link: https://lore.kernel.org/r/20221112094310.3633291-1-yangyingliang@huawei.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/scsi/fcoe/fcoe_sysfs.c