OSDN Git Service

sync: Fix a race condition between release_obj and print_obj
authorAlistair Strachan <alistair.strachan@imgtec.com>
Wed, 10 Apr 2013 23:35:14 +0000 (16:35 -0700)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 13 Feb 2014 15:50:39 +0000 (23:50 +0800)
commit1fade5ff97aab9bf16ba84a25df1d152be95d8d1
tree7b9303edc4f2bea80d8802c3dccad00ece64f596
parent846f34fed72f303396aa1a258bfdd32a19c53309
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.

Signed-off-by: Alistair Strachan <alistair.strachan@imgtec.com>
(cherry picked from commit 3bfc1e9e0c7d0c0e3f52ee1f3803482416afa295)

Change-Id: Ib2b2b23fde5be34016f9d86b8b9c5e561b56cd4c
drivers/staging/android/sync.c