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

[ Upstream commit 916288bca658ab073bb2c2b0bc74654df277999f ]

If device_register() fails in cxl_pci_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: 80eb61d8c430 ("cxl: Driver code for powernv PCIe based cards for userspace access")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Acked-by: Frederic Barrat <fbarrat@linux.ibm.com>
Acked-by: Andrew Donnellan <ajd@linux.ibm.com>
Link: https://lore.kernel.org/r/20221111145440.2426970-2-yangyingliang@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/misc/cxl/pci.c