OSDN Git Service

thermal-core: Use rcu for accessing sensor list
authorRam Chandrasekar <rkumbako@codeaurora.org>
Thu, 15 Oct 2015 21:36:35 +0000 (15:36 -0600)
committerRam Chandrasekar <rkumbako@codeaurora.org>
Fri, 2 Dec 2016 22:42:46 +0000 (15:42 -0700)
commitc975089fd596688e1271339c7914892f20cc58bb
tree635155a53ac6fb01b0d7a73e3cc5894fcb60f002
parentb979f780bfe70f299455bf9e10f206cb58951b6c
thermal-core: Use rcu for accessing sensor list

Sensor temperature read function traverses the
sensor list every time without using any lock. If the
list is undergoing mutation when it is traversed, it may
result in memory violation. For example, the new element
could have added to the list before updating the
next pointer due to out of order execution. This could result
in either NULL pointer dereference or unassigned memory access
violation. Using a lock every time when temperature
is read may mutually exclude it from list mutation, but it impacts
the performance. Sensor addition is an infrequent operation
when compared to sensor temperature read. So adding a lock
to protect against this infrequent operation will add overhead
and deter performance. Use of list_for_each_entry_safe() function
for traversing, won't help. Because this function can help
only if the traversal loop removes the current element, that
is pointed by this iteration.

Use RCU when traversing and updating the list to avoid locks.
RCU ensures list traversal safe addition or deletion happens
and doesn't block the frequent read operation. Replace the
list_for_each_entry_safe() function with rcu safe list
traversal function list_for_each_entry_rcu(), wherever it is
applicable.

Change-Id: I4c05fefa6906ecad408dfd4407b60bc051366f8c
Signed-off-by: Ram Chandrasekar <rkumbako@codeaurora.org>
drivers/thermal/thermal_core.c