diff options
author | Alistair Strachan <alistair.strachan@imgtec.com> | 2014-02-04 19:08:36 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-02-07 12:03:16 -0500 |
commit | 5cf045f54d31894ec59ee741e01fa258be2ba0fb (patch) | |
tree | 1820fb33350fdd10a8bf56bd9b1eebcea8f76836 | |
parent | bbd9ae8a05e05a608ff9158cf3b95be7b857a6fa (diff) |
staging: sync: Fix a race condition between release_obj and print_obj
Before this change, a timeline would only be removed from the timeline
list *after* the sync driver had its release_obj() called. However, the
driver's release_obj() may free resources needed by print_obj().
Although the timeline list is locked when print_obj() is called, it is
not locked when release_obj() is called. If one CPU was in print_obj()
when another was in release_obj(), the print_obj() may make unsafe
accesses.
It is not actually necessary to hold the timeline list lock when calling
release_obj() if the call is made after the timeline is unlinked from
the list, since there is no possibility another thread could be in --
or enter -- print_obj() for that timeline.
This change moves the release_obj() call to after the timeline is
unlinked, preventing the above race from occurring.
Cc: Colin Cross <ccross@android.com>
Cc: Android Kernel Team <kernel-team@android.com>
Signed-off-by: Alistair Strachan <alistair.strachan@imgtec.com>
[jstultz: minor commit subject tweak]
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/staging/android/sync.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 38e5d3b5ed9b..b7fcaab0acea 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c | |||
@@ -79,13 +79,13 @@ static void sync_timeline_free(struct kref *kref) | |||
79 | container_of(kref, struct sync_timeline, kref); | 79 | container_of(kref, struct sync_timeline, kref); |
80 | unsigned long flags; | 80 | unsigned long flags; |
81 | 81 | ||
82 | if (obj->ops->release_obj) | ||
83 | obj->ops->release_obj(obj); | ||
84 | |||
85 | spin_lock_irqsave(&sync_timeline_list_lock, flags); | 82 | spin_lock_irqsave(&sync_timeline_list_lock, flags); |
86 | list_del(&obj->sync_timeline_list); | 83 | list_del(&obj->sync_timeline_list); |
87 | spin_unlock_irqrestore(&sync_timeline_list_lock, flags); | 84 | spin_unlock_irqrestore(&sync_timeline_list_lock, flags); |
88 | 85 | ||
86 | if (obj->ops->release_obj) | ||
87 | obj->ops->release_obj(obj); | ||
88 | |||
89 | kfree(obj); | 89 | kfree(obj); |
90 | } | 90 | } |
91 | 91 | ||