Skip to contentSkip to conversation

media: amphion: Fix error handling in vpu_driver_init()

PATCH In review Yuan Can 2 participants 2 messages Nov 11, 2022 – Nov 14, 2022

Subsystems (2)
lore
Share & tools
lore

Yuan Can

author
#0 lore raw

PATCH 1/1 media: amphion: Fix error handling in vpu_driver_init()

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")
---
 drivers/media/platform/amphion/vpu_drv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/platform/amphion/vpu_drv.c +5 -1
index 9d5a5075343d..f01ce49d27e8 100644
@@ -245,7 +245,11 @@ static int __init vpu_driver_init(void)
 	if (ret)
 		return ret;
 
-	return vpu_core_driver_init();
+	ret = vpu_core_driver_init();
+	if (ret)
+		platform_driver_unregister(&amphion_vpu_driver);
+
+	return ret;
 }
 
 static void __exit vpu_driver_exit(void)
Signature · 1 line
2.17.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines

From: Yuan Can <[email protected]>
Sent: 2022年11月11日 14:09
To: Ming Qian <[email protected]>; [email protected]; Eagle Zhou <[email protected]>; [email protected]; [email protected]; [email protected]
Cc: [email protected]
Subject: [PATCH] media: amphion: Fix error handling in vpu_driver_init()

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

Quoted 7 lines
  # 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")
Quoted 24 lines

---
drivers/media/platform/amphion/vpu_drv.c | 6 +++++-

1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/platform/amphion/vpu_drv.c +5 -2
index 9d5a5075343d..f01ce49d27e8 100644
@@ -245,7 +245,11 @@ static int __init vpu_driver_init(void)
 	if (ret)
 		return ret;
 
-	return vpu_core_driver_init();
+	ret = vpu_core_driver_init();
+	if (ret)
+		platform_driver_unregister(&amphion_vpu_driver);
+
+	return ret;
 }
 
 static void __exit vpu_driver_exit(void)
--

2.17.1