Skip to content

Commit 64aaeb7

Browse files
committed
OPP: Protect lazy_opp_tables list with opp_table_lock
The `opp_table_lock` lock is already used to protect the list elsewhere, use it while adding or removing entries from it. Reported-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Tested-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
1 parent 167eb2b commit 64aaeb7

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

drivers/opp/of.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "opp.h"
2323

24-
/* OPP tables with uninitialized required OPPs */
24+
/* OPP tables with uninitialized required OPPs, protected by opp_table_lock */
2525
static LIST_HEAD(lazy_opp_tables);
2626

2727
/*
@@ -148,7 +148,10 @@ static void _opp_table_free_required_tables(struct opp_table *opp_table)
148148

149149
opp_table->required_opp_count = 0;
150150
opp_table->required_opp_tables = NULL;
151+
152+
mutex_lock(&opp_table_lock);
151153
list_del(&opp_table->lazy);
154+
mutex_unlock(&opp_table_lock);
152155
}
153156

154157
/*
@@ -197,8 +200,15 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table,
197200
}
198201

199202
/* Let's do the linking later on */
200-
if (lazy)
203+
if (lazy) {
204+
/*
205+
* The OPP table is not held while allocating the table, take it
206+
* now to avoid corruption to the lazy_opp_tables list.
207+
*/
208+
mutex_lock(&opp_table_lock);
201209
list_add(&opp_table->lazy, &lazy_opp_tables);
210+
mutex_unlock(&opp_table_lock);
211+
}
202212
else
203213
_update_set_required_opps(opp_table);
204214

0 commit comments

Comments
 (0)