ANDROID: trusty-ipc: Fix lock protection of shared_handles
And move uses of shared_handles symbol to within critical sections
protected by shared_handles_lock to improve readability.
Bug: 206813152
Change-Id: I965dedaa1fafbf610620cf7dffe5665271099281
Signed-off-by: Tri Vo <[email protected]>
diff --git a/drivers/trusty/trusty-ipc.c b/drivers/trusty/trusty-ipc.c
index b553482..46d1610 100644
--- a/drivers/trusty/trusty-ipc.c
+++ b/drivers/trusty/trusty-ipc.c
@@ -288,7 +288,13 @@
{
struct tipc_virtio_dev *vds =
container_of(kref, struct tipc_virtio_dev, refcount);
- /* If this WARN triggers, we're leaking remote memory references. */
+ /*
+ * If this WARN triggers, we're leaking remote memory references.
+ *
+ * No need to lock shared_handles_lock. All references to this lock
+ * should already be gone by this point, since we are freeing it in this
+ * function.
+ */
WARN_ON(!RB_EMPTY_ROOT(&vds->shared_handles));
kfree(vds);
}
@@ -554,11 +560,12 @@
*new_handle)
{
struct tipc_virtio_dev *vds = new_handle->vds;
- struct rb_node **new = &vds->shared_handles.rb_node;
+ struct rb_node **new;
struct rb_node *parent = NULL;
mutex_lock(&vds->shared_handles_lock);
+ new = &vds->shared_handles.rb_node;
while (*new) {
struct tipc_shared_handle *handle =
rb_entry(*new, struct tipc_shared_handle, node);
@@ -584,11 +591,12 @@
trusty_shared_mem_id_t
obj_id)
{
- struct rb_node *node = vds->shared_handles.rb_node;
+ struct rb_node *node;
struct tipc_shared_handle *out = NULL;
mutex_lock(&vds->shared_handles_lock);
+ node = vds->shared_handles.rb_node;
while (node) {
struct tipc_shared_handle *handle =
rb_entry(node, struct tipc_shared_handle, node);