]> git.baikalelectronics.ru Git - kernel.git/commitdiff
media: platform: exynos4-is: Fix error handling in fimc_md_init()
authorYuan Can <yuancan@huawei.com>
Fri, 11 Nov 2022 06:08:53 +0000 (06:08 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Jan 2023 10:41:04 +0000 (11:41 +0100)
[ Upstream commit b434422c45282a0573d8123239abc41fa72665d4 ]

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: 555927a6162f ("[media] s5p-fimc: Add the media device driver")
Signed-off-by: Yuan Can <yuancan@huawei.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/media/platform/exynos4-is/fimc-core.c
drivers/media/platform/exynos4-is/media-dev.c

index cde60fbb23a88d02493ab785e47db077be3ca50b..5b06c83f5c99d607a8230cfd84165fc6d9ba3c1f 100644 (file)
@@ -1231,7 +1231,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);
 }
index a07d796f63df0daf967275c4de381895aa33844b..707feb35a95076dea73a246901aaddb376f0805f 100644 (file)
@@ -1581,7 +1581,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)