Commit 48ecee61 authored by Yuan Can's avatar Yuan Can Committed by Mauro Carvalho Chehab

media: platform: exynos4-is: Fix error handling in fimc_md_init()

A problem about modprobe s5p_fimc failed is triggered with the
following log given:

 [  272.075275] Error: Driver 'exynos4-fimc' is already registered, aborting...
 modprobe: ERROR: could not insert 's5p_fimc': Device or resource busy

The reason is that fimc_md_init() returns platform_driver_register()
directly without checking its return value, if platform_driver_register()
failed, it returns without unregister fimc_driver, resulting the
s5p_fimc can never be installed later.
A simple call graph is shown as below:

 fimc_md_init()
   fimc_register_driver() # register fimc_driver
   platform_driver_register()
     platform_driver_register()
       driver_register()
         bus_add_driver()
           dev = kzalloc(...) # OOM happened
   # return without unregister fimc_driver

Fix by unregister fimc_driver when platform_driver_register() returns
error.

Fixes: d3953223 ("[media] s5p-fimc: Add the media device driver")
Signed-off-by: default avatarYuan Can <yuancan@huawei.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@kernel.org>
parent ba7c0d34
......@@ -1173,7 +1173,7 @@ int __init fimc_register_driver(void)
return platform_driver_register(&fimc_driver);
}
void __exit fimc_unregister_driver(void)
void fimc_unregister_driver(void)
{
platform_driver_unregister(&fimc_driver);
}
......@@ -1584,7 +1584,11 @@ static int __init fimc_md_init(void)
if (ret)
return ret;
return platform_driver_register(&fimc_md_driver);
ret = platform_driver_register(&fimc_md_driver);
if (ret)
fimc_unregister_driver();
return ret;
}
static void __exit fimc_md_exit(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment