]> git.baikalelectronics.ru Git - kernel.git/commit
cxl: fix possible null-ptr-deref in cxl_guest_init_afu|adapter()
authorYang Yingliang <yangyingliang@huawei.com>
Fri, 11 Nov 2022 14:54:39 +0000 (22:54 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:24 +0000 (11:41 +0100)
commitc17cca9f0eca0a39276f8df175bf8ec89b449448
tree5c2d098b0b314b0b0186b96ef5f6958b26024e23
parent57687506bd6ba6783b5f2fc325aaf8fa242abdbd
cxl: fix possible null-ptr-deref in cxl_guest_init_afu|adapter()

[ Upstream commit f7668fe20e22204dc5ad7c78243d82979d01ab0b ]

If device_register() fails in cxl_register_afu|adapter(), the device
is not added, device_unregister() can not be called in the error path,
otherwise it will cause a null-ptr-deref because of removing not added
device.

As comment of device_register() says, it should use put_device() to give
up the reference in the error path. So split device_unregister() into
device_del() and put_device(), then goes to put dev when register fails.

Fixes: 05d3495fbe8b ("cxl: Add guest-specific code")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Acked-by: Andrew Donnellan <ajd@linux.ibm.com>
Acked-by: Frederic Barrat <fbarrat@linux.ibm.com>
Link: https://lore.kernel.org/r/20221111145440.2426970-1-yangyingliang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/misc/cxl/guest.c