media: amphion: Fix error handling in vpu_driver_init()
authorYuan Can <yuancan@huawei.com>
Fri, 11 Nov 2022 06:09:26 +0000 (06:09 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:13 +0000 (13:32 +0100)
commitd72bff7e6cc324b31b62826d5fe279c0390e2335
tree5c72eedbcf61ec8e529fdd5df32cf8c8c990462b
parentabc73b6739a1943e18438b83d351614858e4cbce
media: amphion: Fix error handling in vpu_driver_init()

[ Upstream commit a95cc6d11aae16a7b2d043b073a40de81bbea689 ]

A problem about modprobe amphion-vpu failed is triggered with the
following log given:

 [ 2208.634841] Error: Driver 'amphion-vpu' is already registered, aborting...
 modprobe: ERROR: could not insert 'amphion_vpu': Device or resource busy

The reason is that vpu_driver_init() returns vpu_core_driver_init()
directly without checking its return value, if vpu_core_driver_init()
failed, it returns without unregister amphion_vpu_driver, resulting the
amphion-vpu can never be installed later.
A simple call graph is shown as below:

 vpu_driver_init()
   platform_driver_register() # register amphion_vpu_driver
   vpu_core_driver_init()
     platform_driver_register()
       driver_register()
         bus_add_driver()
           dev = kzalloc(...) # OOM happened
   # return without unregister amphion_vpu_driver

Fix by unregister amphion_vpu_driver when vpu_core_driver_init() returns
error.

Fixes: b50a64fc54af ("media: amphion: add amphion vpu device driver")
Signed-off-by: Yuan Can <yuancan@huawei.com>
Reviewed-by: ming_qian <ming.qian@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/platform/amphion/vpu_drv.c