Skip to contentSkip to conversation

s390/vfio-ap: Unregister the debug area on init failure

PATCH In review Haoxiang Li 3 participants 4 messages Dec 3 – Dec 4

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390/vfio-ap: Unregister the debug area on init failure

vfio_ap_dbf_info_init() registers a debug area via debug_register(). However, vfio_ap_init() does not unregister it if any subsequent initialization step fails, leaving the debug area registered.

Fix this by calling debug_unregister() after unwinding the resources acquired during initialization.

Fixes a084c44eaa6a ("s390-vfio-ap: introduces s390 kernel debug feature for vfio_ap device driver")
---
 drivers/s390/crypto/vfio_ap_drv.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/s390/crypto/vfio_ap_drv.c +17 -13
index 8e69ed286bb9..9236c77e6a4c 100644
@@ -173,28 +173,32 @@ static int __init vfio_ap_init(void)
 		return ret;
 
 	/* If there are no AP instructions, there is nothing to pass through. */
-	if (!ap_instructions_available())
-		return -ENODEV;
+	if (!ap_instructions_available()) {
+		ret = -ENODEV;
+		goto err_debug;
+	}
 
 	ret = vfio_ap_matrix_dev_create();
 	if (ret)
-		return ret;
+		goto err_debug;
 
 	ret = ap_driver_register(&vfio_ap_drv, THIS_MODULE, VFIO_AP_DRV_NAME);
-	if (ret) {
-		vfio_ap_matrix_dev_destroy();
-		return ret;
-	}
+	if (ret)
+		goto err_matrix;
 
 	ret = vfio_ap_mdev_register();
-	if (ret) {
-		ap_driver_unregister(&vfio_ap_drv);
-		vfio_ap_matrix_dev_destroy();
-
-		return ret;
-	}
+	if (ret)
+		goto err_ap_driver;
 
 	return 0;
+
+err_ap_driver:
+	ap_driver_unregister(&vfio_ap_drv);
+err_matrix:
+	vfio_ap_matrix_dev_destroy();
+err_debug:
+	debug_unregister(vfio_ap_dbf_info);
+	return ret;
 }
 
 static void __exit vfio_ap_exit(void)
Signature · 1 line
2.25.1
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

vfio_ap_dbf_info_init() registers a debug area via debug_register(). However, vfio_ap_init() does not unregister it if any subsequent initialization step fails, leaving the debug area registered.

Fix this by calling debug_unregister() after unwinding the resources acquired during initialization.

Fixes a084c44eaa6a ("s390-vfio-ap: introduces s390 kernel debug feature for vfio_ap device driver")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Haoxiang Li
Quoted 6 lines · Haoxiang Li

vfio_ap_dbf_info_init() registers a debug area via debug_register(). However, vfio_ap_init() does not unregister it if any subsequent initialization step fails, leaving the debug area registered.

Fix this by calling debug_unregister() after unwinding the resources acquired during initialization.

Why not just move the vfio_ap_dbf_info_init() call to the end of the function? That would eliminate the need for the goto's

Quoted 57 lines
Fixes a084c44eaa6a ("s390-vfio-ap: introduces s390 kernel debug feature for vfio_ap device driver")
---
  drivers/s390/crypto/vfio_ap_drv.c | 30 +++++++++++++++++-------------
  1 file changed, 17 insertions(+), 13 deletions(-)
drivers/s390/crypto/vfio_ap_drv.c +17 -13
index 8e69ed286bb9..9236c77e6a4c 100644
@@ -173,28 +173,32 @@ static int __init vfio_ap_init(void)
  		return ret;
 
  	/* If there are no AP instructions, there is nothing to pass through. */
-	if (!ap_instructions_available())
-		return -ENODEV;
+	if (!ap_instructions_available()) {
+		ret = -ENODEV;
+		goto err_debug;
+	}
 
  	ret = vfio_ap_matrix_dev_create();
  	if (ret)
-		return ret;
+		goto err_debug;
 
  	ret = ap_driver_register(&vfio_ap_drv, THIS_MODULE, VFIO_AP_DRV_NAME);
-	if (ret) {
-		vfio_ap_matrix_dev_destroy();
-		return ret;
-	}
+	if (ret)
+		goto err_matrix;
 
  	ret = vfio_ap_mdev_register();
-	if (ret) {
-		ap_driver_unregister(&vfio_ap_drv);
-		vfio_ap_matrix_dev_destroy();
-
-		return ret;
-	}
+	if (ret)
+		goto err_ap_driver;
 
  	return 0;
+
+err_ap_driver:
+	ap_driver_unregister(&vfio_ap_drv);
+err_matrix:
+	vfio_ap_matrix_dev_destroy();
+err_debug:
+	debug_unregister(vfio_ap_dbf_info);
+	return ret;
  }
 
  static void __exit vfio_ap_exit(void)
#3 lore raw

Hi,

Quoted 4 lines · Anthony Krowiak

Why not just move the vfio_ap_dbf_info_init() call to the end of the function? That would eliminate the need for the goto's

Thanks for the suggestion!

Moving vfio_ap_dbf_info_init() to the end would work. But since vfio_ap_dbf_info_init() can itself fail, we would still need to unwind the previously acquired resources. I don't think this would simplify the error handling much.

Best Regards,
Haoxiang Li