OSDN Git Service
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>