msm: msm_bus: Add mutex to protect node_list

Static variable node_list list need to be protected with a mutex
to prevent race conditions and use after free cases.

Change-Id: I4790b06712b8a8b401f43418cfcc53b415fb0019
Signed-off-by: David Dai <daidavid1@codeaurora.org>
Signed-off-by: Odelu Kukatla <okukatla@codeaurora.org>
This commit is contained in:
David Dai 2017-04-26 14:52:24 -07:00 committed by Odelu Kukatla
parent 75a9d0fee5
commit 346c7ec716

View file

@ -1,4 +1,4 @@
/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. /* Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and * it under the terms of the GNU General Public License version 2 and
@ -410,8 +410,10 @@ void print_all_rules(void)
{ {
struct rule_node_info *node_it = NULL; struct rule_node_info *node_it = NULL;
mutex_lock(&msm_bus_rules_lock);
list_for_each_entry(node_it, &node_list, link) list_for_each_entry(node_it, &node_list, link)
print_rules(node_it); print_rules(node_it);
mutex_unlock(&msm_bus_rules_lock);
} }
void print_rules_buf(char *buf, int max_buf) void print_rules_buf(char *buf, int max_buf)
@ -421,6 +423,7 @@ void print_rules_buf(char *buf, int max_buf)
int i; int i;
int cnt = 0; int cnt = 0;
mutex_lock(&msm_bus_rules_lock);
list_for_each_entry(node_it, &node_list, link) { list_for_each_entry(node_it, &node_list, link) {
cnt += scnprintf(buf + cnt, max_buf - cnt, cnt += scnprintf(buf + cnt, max_buf - cnt,
"\n Now printing rules for Node %d cur_rule %d\n", "\n Now printing rules for Node %d cur_rule %d\n",
@ -452,6 +455,7 @@ void print_rules_buf(char *buf, int max_buf)
node_rule->rule_ops.mode); node_rule->rule_ops.mode);
} }
} }
mutex_unlock(&msm_bus_rules_lock);
} }
static int copy_rule(struct bus_rule_type *src, struct rules_def *node_rule, static int copy_rule(struct bus_rule_type *src, struct rules_def *node_rule,
@ -721,11 +725,12 @@ bool msm_rule_are_rules_registered(void)
{ {
bool ret = false; bool ret = false;
mutex_lock(&msm_bus_rules_lock);
if (list_empty(&node_list)) if (list_empty(&node_list))
ret = false; ret = false;
else else
ret = true; ret = true;
mutex_unlock(&msm_bus_rules_lock);
return ret; return ret;
} }