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)
committerJassi Brar <jaswinder.singh@linaro.org>
Mon, 19 Dec 2022 02:40:30 +0000 (20:40 -0600)
commita6792a0cdef0b1c2d77920246283a72537e60e94
treea1298cbfd4d5a1d12a4131ffc63b0f578cbb1276
parentacabe12c6106b105ac8285d6d5ba2aeeab74fd47
mailbox: zynq-ipi: fix error handling while device_register() fails

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>
drivers/mailbox/zynqmp-ipi-mailbox.c