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:32:55 +0000 (13:32 +0100)
commit3fcf079958c00d83c51e4f250abf2c77fe9cc1b9
treedd52ba0678905ee1ef917b1e3945b23ae63991cd
parent525e54789c2bd75723556f5b27d40d4cbfe6493d
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