FROMLIST: binder: make binder_last_id an atomic
authorTodd Kjos <tkjos@google.com>
Thu, 25 May 2017 17:56:00 +0000 (10:56 -0700)
committerTodd Kjos <tkjos@google.com>
Thu, 13 Jul 2017 15:34:19 +0000 (08:34 -0700)
(from https://patchwork.kernel.org/patch/9817809/)

Use an atomic for binder_last_id to avoid locking it

Change-Id: I582c48be4bd04a17d6c96c9a4093c3ade56c47cd
Signed-off-by: Todd Kjos <tkjos@google.com>
drivers/android/binder.c

index a8e56a4c3070be5ab7635d2c8d3e9963fd9d3cea..970c21d1478c1285b52ef37a8653d82c72528870 100644 (file)
@@ -58,7 +58,7 @@ static DEFINE_SPINLOCK(binder_dead_nodes_lock);
 
 static struct dentry *binder_debugfs_dir_entry_root;
 static struct dentry *binder_debugfs_dir_entry_proc;
-static int binder_last_id;
+static atomic_t binder_last_id;
 
 #define BINDER_DEBUG_ENTRY(name) \
 static int binder_##name##_open(struct inode *inode, struct file *file) \
@@ -495,7 +495,7 @@ static struct binder_node *binder_new_node(struct binder_proc *proc,
        binder_stats_created(BINDER_STAT_NODE);
        rb_link_node(&node->rb_node, parent, p);
        rb_insert_color(&node->rb_node, &proc->nodes);
-       node->debug_id = ++binder_last_id;
+       node->debug_id = atomic_inc_return(&binder_last_id);
        node->proc = proc;
        node->ptr = ptr;
        node->cookie = cookie;
@@ -639,7 +639,7 @@ static struct binder_ref *binder_get_ref_for_node(struct binder_proc *proc,
        if (new_ref == NULL)
                return NULL;
        binder_stats_created(BINDER_STAT_REF);
-       new_ref->debug_id = ++binder_last_id;
+       new_ref->debug_id = atomic_inc_return(&binder_last_id);
        new_ref->proc = proc;
        new_ref->node = node;
        rb_link_node(&new_ref->rb_node_node, parent, p);
@@ -1527,7 +1527,7 @@ static void binder_transaction(struct binder_proc *proc,
        }
        binder_stats_created(BINDER_STAT_TRANSACTION_COMPLETE);
 
-       t->debug_id = ++binder_last_id;
+       t->debug_id = atomic_inc_return(&binder_last_id);
        e->debug_id = t->debug_id;
 
        if (reply)