]> git.baikalelectronics.ru Git - kernel.git/commit
mailbox: zynq-ipi: fix error handling while device_register() fails
authorYang Yingliang <yangyingliang@huawei.com>
Thu, 10 Nov 2022 15:08:22 +0000 (23:08 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:33 +0000 (11:41 +0100)
commit5e260db58e017ba31dc2ed97a5bfc3af4c1019f4
tree5e0e7d9d1b9a592d5a73aeaaea7fcb9851ca5d11
parentc1119ffd3d5ca53ff2d6c5d9cdab23075fb9ff43
mailbox: zynq-ipi: fix error handling while device_register() fails

[ Upstream commit 7457d21949961aa7dcbe885b2453f4d0dad35ad3 ]

If device_register() fails, it has two issues:
1. The name allocated by dev_set_name() is leaked.
2. The parent of device is not NULL, device_unregister() is called
   in zynqmp_ipi_free_mboxes(), it will lead a kernel crash because
   of removing not added device.

Call put_device() to give up the reference, so the name is freed in
kobject_cleanup(). Add device registered check in zynqmp_ipi_free_mboxes()
to avoid null-ptr-deref.

Fixes: 4a364c29c7e1 ("mailbox: ZynqMP IPI mailbox controller")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/mailbox/zynqmp-ipi-mailbox.c