srcu_init_notifier_head(&opp_table->srcu_head);
INIT_LIST_HEAD(&opp_table->opp_list);
+ mutex_init(&opp_table->lock);
/* Secure the device table modification */
list_add_rcu(&opp_table->node, &opp_tables);
/* dev_list must be empty now */
WARN_ON(!list_empty(&opp_table->dev_list));
+ mutex_destroy(&opp_table->lock);
list_del_rcu(&opp_table->node);
call_srcu(&opp_table->srcu_head.srcu, &opp_table->rcu_head,
_kfree_device_rcu);
*/
static void _opp_remove(struct opp_table *opp_table, struct dev_pm_opp *opp)
{
+ mutex_lock(&opp_table->lock);
+
/*
* Notify the changes in the availability of the operable
* frequency/voltage list.
list_del_rcu(&opp->node);
call_srcu(&opp_table->srcu_head.srcu, &opp->rcu_head, _kfree_opp_rcu);
+ mutex_unlock(&opp_table->lock);
+
_remove_opp_table(opp_table);
}
if (IS_ERR(opp_table))
goto unlock;
+ mutex_lock(&opp_table->lock);
+
list_for_each_entry(opp, &opp_table->opp_list, node) {
if (opp->rate == freq) {
found = true;
}
}
+ mutex_unlock(&opp_table->lock);
+
if (!found) {
dev_warn(dev, "%s: Couldn't find OPP with freq: %lu\n",
__func__, freq);
struct opp_table *opp_table)
{
struct dev_pm_opp *opp;
- struct list_head *head = &opp_table->opp_list;
+ struct list_head *head;
int ret;
/*
* loop, don't replace it with head otherwise it will become an infinite
* loop.
*/
+ mutex_lock(&opp_table->lock);
+ head = &opp_table->opp_list;
+
list_for_each_entry_rcu(opp, &opp_table->opp_list, node) {
if (new_opp->rate > opp->rate) {
head = &opp->node;
new_opp->supplies[0].u_volt, new_opp->available);
/* Should we compare voltages for all regulators here ? */
- return opp->available &&
- new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? -EBUSY : -EEXIST;
+ ret = opp->available &&
+ new_opp->supplies[0].u_volt == opp->supplies[0].u_volt ? -EBUSY : -EEXIST;
+
+ mutex_unlock(&opp_table->lock);
+ return ret;
}
- new_opp->opp_table = opp_table;
list_add_rcu(&new_opp->node, head);
+ mutex_unlock(&opp_table->lock);
+
+ new_opp->opp_table = opp_table;
ret = opp_debug_create_one(new_opp, opp_table);
if (ret)
goto unlock;
}
+ mutex_lock(&opp_table->lock);
+
/* Do we have the frequency? */
list_for_each_entry(tmp_opp, &opp_table->opp_list, node) {
if (tmp_opp->rate == freq) {
break;
}
}
+
+ mutex_unlock(&opp_table->lock);
+
if (IS_ERR(opp)) {
r = PTR_ERR(opp);
goto unlock;
* @rcu_head: RCU callback head used for deferred freeing
* @dev_list: list of devices that share these OPPs
* @opp_list: table of opps
+ * @lock: mutex protecting the opp_list.
* @np: struct device_node pointer for opp's DT node.
* @clock_latency_ns_max: Max clock latency in nanoseconds.
* @shared_opp: OPP is shared between multiple devices.
struct rcu_head rcu_head;
struct list_head dev_list;
struct list_head opp_list;
+ struct mutex lock;
struct device_node *np;
unsigned long clock_latency_ns_max;