diff mbox series

[CLOUD-DEV,v1,1/1] drv: driver: fix devio registration race

Message ID 1497873608-11776-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [CLOUD-DEV,v1,1/1] drv: driver: fix devio registration race | expand

Commit Message

Github ODP bot June 19, 2017, noon UTC
From: Josep Puigdemont <josep.puigdemont@linaro.org>


This fixes a race condition that could arise when registering a devio.

Signed-off-by: Josep Puigdemont <josep.puigdemont@linaro.org>

---
/** Email created from pull request 47 (joseppc:fix-devio-race)
 ** https://github.com/Linaro/odp/pull/47
 ** Patch: https://github.com/Linaro/odp/pull/47.patch
 ** Base sha: f2a1712bdb379b2eb2c6e470a2f2d9a1302f344f
 ** Merge commit sha: ea375d3e4ac5b446546a8e59e03f7e88ac982377
 **/
 platform/linux-generic/drv_driver.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-generic/drv_driver.c b/platform/linux-generic/drv_driver.c
index 46cbdba9..3c918def 100644
--- a/platform/linux-generic/drv_driver.c
+++ b/platform/linux-generic/drv_driver.c
@@ -529,7 +529,7 @@  odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param)
 	 * sure no devio providing the same interface using th esame enumerator
 	 * already exists:
 	 */
-	devio_list_read_lock();
+	devio_list_write_lock();
 	devio = devio_lst.head;
 	while (devio) {
 		if ((strncmp(param->api_name, devio->param.api_name,
@@ -539,12 +539,11 @@  odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param)
 			ODP_ERR("a devio providing interface '%s' for devices "
 				"of type '%s' is already registered\n!",
 				param->api_name, param->enumr_api_name);
-			devio_list_read_unlock();
+			devio_list_write_unlock();
 			return ODPDRV_DEVIO_INVALID;
 		}
 		devio = devio->next;
 	}
-	devio_list_read_unlock();
 
 	/* allocate memory for the new devio:
 	 * If init_global has not been done yet, then, we cannot allocate
@@ -561,13 +560,16 @@  odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param)
 
 	if (init_global_status == UNDONE) {
 		devio = malloc(sizeof(_odpdrv_devio_t));
-		if (!devio)
+		if (!devio) {
+			devio_list_write_unlock();
 			return ODPDRV_DEVIO_INVALID;
+		}
 		devio->pool = NULL;
 	} else {
 		devio = _odp_ishm_pool_alloc(list_elt_pool,
 					     sizeof(_odpdrv_devio_t));
 		if (!devio) {
+			devio_list_write_unlock();
 			ODP_ERR("_odp_ishm_pool_alloc failed!\n");
 			return ODPDRV_DEVIO_INVALID;
 		}
@@ -576,7 +578,6 @@  odpdrv_devio_t odpdrv_devio_register(odpdrv_devio_param_t *param)
 
 	/* save init parameters and insert devio in list */
 	devio->param = *param;
-	devio_list_write_lock();
 	devio->next = devio_lst.head;
 	devio_lst.head = devio;
 	devio_list_write_unlock();