diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2020-12-18 09:52:36 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2020-12-18 09:54:39 +0000 |
commit | 3d6caf71a3e988cd125eb9efdd0a7cdcd0451673 (patch) | |
tree | bfeeede586ba7e72a09d810190e937382581e7f3 | |
parent | b8b1391f7bfff83397ddc47c0083c2c7ed06be37 (diff) |
lib: Fix double lock in igt_free_spins()
igt_free_spins() took the lock to iterate the list, igt_spin_free() took
the lock to remove the list element. We only want one.
Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/2823
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
-rw-r--r-- | lib/igt_dummyload.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/lib/igt_dummyload.c b/lib/igt_dummyload.c index b29d12af..28fcbf81 100644 --- a/lib/igt_dummyload.c +++ b/lib/igt_dummyload.c @@ -538,23 +538,8 @@ void igt_spin_end(igt_spin_t *spin) __sync_synchronize(); } -/** - * igt_spin_free: - * @fd: open i915 drm file descriptor - * @spin: spin state from igt_spin_new() - * - * This function does the necessary post-processing after starting a - * spin with igt_spin_new() and then frees it. - */ -void igt_spin_free(int fd, igt_spin_t *spin) +static void __igt_spin_free(int fd, igt_spin_t *spin) { - if (!spin) - return; - - pthread_mutex_lock(&list_lock); - igt_list_del(&spin->link); - pthread_mutex_unlock(&list_lock); - if (spin->timerfd >= 0) { pthread_cancel(spin->timer_thread); igt_assert(pthread_join(spin->timer_thread, NULL) == 0); @@ -580,6 +565,26 @@ void igt_spin_free(int fd, igt_spin_t *spin) free(spin); } +/** + * igt_spin_free: + * @fd: open i915 drm file descriptor + * @spin: spin state from igt_spin_new() + * + * This function does the necessary post-processing after starting a + * spin with igt_spin_new() and then frees it. + */ +void igt_spin_free(int fd, igt_spin_t *spin) +{ + if (!spin) + return; + + pthread_mutex_lock(&list_lock); + igt_list_del(&spin->link); + pthread_mutex_unlock(&list_lock); + + __igt_spin_free(fd, spin); +} + void igt_terminate_spins(void) { struct igt_spin *iter; @@ -596,7 +601,8 @@ void igt_free_spins(int i915) pthread_mutex_lock(&list_lock); igt_list_for_each_entry_safe(iter, next, &spin_list, link) - igt_spin_free(i915, iter); + __igt_spin_free(i915, iter); + IGT_INIT_LIST_HEAD(&spin_list); pthread_mutex_unlock(&list_lock); } |