Skip to contentSkip to conversation

tests/drm_import_export: Always loop with mutex held

PATCH In review Mika Kuoppala 2 participants 2 messages Nov 25, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/drm_import_export: Always loop with mutex held

We assume that lock is held on start of the loop scope. Some paths continuing inside loop didn't adhere to this assumption, causing segfault on unlocking an already unlocked mutex. Fix this by re-aquiring lock always.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=93013

Cc Michał Winiarski <[email protected]>
Cc Thomas Wood <[email protected]>
---
 tests/drm_import_export.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/drm_import_export.c +4 -4
index 49486ab..cfe5f6d 100644
@@ -161,20 +161,20 @@ static void *import_close_thread(void *data)
 				pthread_mutex_unlock(&t->mutex);
 			}
 			else
-				/* We take the lock right after entering the loop */
+				/* Lock should be held on entering the loop */
 				continue;
 		}
+
 		if (bo == NULL) {
 			/*
 			 * If the bo is NULL it means that we've unreferenced in other
 			 * thread - therefore we should expect ENOENT
 			 */
 			igt_assert_eq(errno, ENOENT);
-			continue;
+		} else {
+			drm_intel_bo_unreference(bo);
 		}
 
-		drm_intel_bo_unreference(bo);
-
 		pthread_mutex_lock(&t->mutex);
 	}
 	pthread_mutex_unlock(&t->mutex);
Signature · 6 lines
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Mika Kuoppala

We assume that lock is held on start of the loop scope. Some paths continuing inside loop didn't adhere to this assumption, causing segfault on unlocking an already unlocked mutex. Fix this by re-aquiring lock always.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=93013

Cc Michał Winiarski <[email protected]>
Cc Thomas Wood <[email protected]>
Quoted 34 lines

---
 tests/drm_import_export.c | 8 ++++----

 1 file changed, 4 insertions(+), 4 deletions(-)
tests/drm_import_export.c +0 -0
index 49486ab..cfe5f6d 100644
@@ -161,20 +161,20 @@ static void *import_close_thread(void *data)
  				pthread_mutex_unlock(&t->mutex);
  			}

  else

tests/drm_import_export.c +0 -1
-				/* We take the lock right after

entering the loop */

tests/drm_import_export.c +1 -0
+				/* Lock should be held on entering

the loop */
  continue;
  }
+
  if (bo == NULL) {
  /*
   * If the bo is NULL it means that we've unreferenced in other
   * thread - therefore we should expect ENOENT
   */
  igt_assert_eq(errno, ENOENT);

tests/drm_import_export.c +2 -1
-			continue;
+		} else {
+			drm_intel_bo_unreference(bo);

  }

tests/drm_import_export.c +0 -2
-		drm_intel_bo_unreference(bo);
-
Quoted 3 lines

  pthread_mutex_lock(&t->mutex); }
  pthread_mutex_unlock(&t->mutex);

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx