Skip to contentSkip to conversation

dm-mpath-rdac.c init race

PATCH New Bryn M. Reeves 1 participant 1 message Oct 2, 2007

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

PATCH 1/1 dm-mpath-rdac.c init race

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The current dm-mpath-rdac has a race in the init function since the hw handler is registered with DM core before allocating the workqueue.

This patch just re-orders the allocation to be before the call to dm_register_hw_handler and adds calls to destroys the workqueue in error paths.

Cheers,
Bryn.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org

iD8DBQFHAl606YSQoMYUY94RAoyvAJ44CB5yY5B+6y66c7DgL/nFId+jcgCgwWYX rh+hKlNANqNZRw6KkyrYCL0=
=mzHx
-----END PGP SIGNATURE-----

Re-order the initialisation of dm-rdac to avoid registering the hw handler before the workqueue has been initialised. Closes a race that would potentially give an oops.

drivers/md/Makefile +0 -0
drivers/md/dm-mpath-rdac.c +8 -7
index 16b1613..a3d9d67 100644
@@ -664,20 +664,21 @@ static struct hw_handler_type rdac_handler = {
 
 static int __init rdac_init(void)
 {
-	int r = dm_register_hw_handler(&rdac_handler);
-
-	if (r < 0) {
-		DMERR("%s: register failed %d", RDAC_DM_HWH_NAME, r);
-		return r;
-	}
+	int r;	
 
 	rdac_wkqd = create_singlethread_workqueue("rdac_wkqd");
 	if (!rdac_wkqd) {
 		DMERR("Failed to create workqueue rdac_wkqd.");
-		dm_unregister_hw_handler(&rdac_handler);
 		return -ENOMEM;
 	}
 
+	r = dm_register_hw_handler(&rdac_handler);
+	if (r < 0) {
+		DMERR("%s: register failed %d", RDAC_DM_HWH_NAME, r);
+		destroy_workqueue(rdac_wkqd);
+		return r;
+	}
+
 	DMINFO("%s: version %s loaded", RDAC_DM_HWH_NAME, RDAC_DM_HWH_VER);
 	return 0;
 }