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>
Sat, 31 Dec 2022 12:14:39 +0000 (13:14 +0100)
commit4f05d8e2fb3ab702c2633a74571e1b31cb579985
treef17061f904a75af415829ac5c90caab5c9ea4b37
parent550f403e4604afaca08bcd0f3323e6c9986354c9
mailbox: zynq-ipi: fix error handling while device_register() fails

[ Upstream commit a6792a0cdef0b1c2d77920246283a72537e60e94 ]

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: 4981b82ba2ff ("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