Skip to content

Commit 48b5aae

Browse files
committed
OPP: Remove genpd_virt_dev_lock
All the config operations for OPP tables share common code paths now and none of the other ones have such protection in place. Either all should have it or none. The understanding here is that user won't clear the OPP configs while still using them and so such a case won't happen. We can always come back and use a wider lock for all resource types if required. Also fix the error on failing to allocate memory. Signed-off-by: Viresh Kumar <[email protected]> Reviewed-by: Ulf Hansson <[email protected]>
1 parent c2bebf9 commit 48b5aae

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

drivers/opp/core.c

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ static int _opp_set_required_opps_genpd(struct device *dev,
10761076
{
10771077
struct device **genpd_virt_devs =
10781078
opp_table->genpd_virt_devs ? opp_table->genpd_virt_devs : &dev;
1079-
int index, target, delta, ret = 0;
1079+
int index, target, delta, ret;
10801080

10811081
/* Scaling up? Set required OPPs in normal order, else reverse */
10821082
if (!scaling_down) {
@@ -1089,23 +1089,15 @@ static int _opp_set_required_opps_genpd(struct device *dev,
10891089
delta = -1;
10901090
}
10911091

1092-
/*
1093-
* Acquire genpd_virt_dev_lock to make sure we don't use a genpd_dev
1094-
* after it is freed from another thread.
1095-
*/
1096-
mutex_lock(&opp_table->genpd_virt_dev_lock);
1097-
10981092
while (index != target) {
10991093
ret = _set_performance_state(dev, genpd_virt_devs[index], opp, index);
11001094
if (ret)
1101-
break;
1095+
return ret;
11021096

11031097
index += delta;
11041098
}
11051099

1106-
mutex_unlock(&opp_table->genpd_virt_dev_lock);
1107-
1108-
return ret;
1100+
return 0;
11091101
}
11101102

11111103
/* This is only called for PM domain for now */
@@ -1474,7 +1466,6 @@ static struct opp_table *_allocate_opp_table(struct device *dev, int index)
14741466
return ERR_PTR(-ENOMEM);
14751467

14761468
mutex_init(&opp_table->lock);
1477-
mutex_init(&opp_table->genpd_virt_dev_lock);
14781469
INIT_LIST_HEAD(&opp_table->dev_list);
14791470
INIT_LIST_HEAD(&opp_table->lazy);
14801471

@@ -1510,7 +1501,6 @@ static struct opp_table *_allocate_opp_table(struct device *dev, int index)
15101501
remove_opp_dev:
15111502
_of_clear_opp_table(opp_table);
15121503
_remove_opp_dev(opp_dev, opp_table);
1513-
mutex_destroy(&opp_table->genpd_virt_dev_lock);
15141504
mutex_destroy(&opp_table->lock);
15151505
err:
15161506
kfree(opp_table);
@@ -1678,7 +1668,6 @@ static void _opp_table_kref_release(struct kref *kref)
16781668
list_for_each_entry_safe(opp_dev, temp, &opp_table->dev_list, node)
16791669
_remove_opp_dev(opp_dev, opp_table);
16801670

1681-
mutex_destroy(&opp_table->genpd_virt_dev_lock);
16821671
mutex_destroy(&opp_table->lock);
16831672
kfree(opp_table);
16841673
}
@@ -2395,7 +2384,7 @@ static void _opp_put_config_regulators_helper(struct opp_table *opp_table)
23952384
opp_table->config_regulators = NULL;
23962385
}
23972386

2398-
static void _detach_genpd(struct opp_table *opp_table)
2387+
static void _opp_detach_genpd(struct opp_table *opp_table)
23992388
{
24002389
int index;
24012390

@@ -2449,13 +2438,11 @@ static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev,
24492438
if (!opp_table->required_opp_count)
24502439
return -EPROBE_DEFER;
24512440

2452-
mutex_lock(&opp_table->genpd_virt_dev_lock);
2453-
24542441
opp_table->genpd_virt_devs = kcalloc(opp_table->required_opp_count,
24552442
sizeof(*opp_table->genpd_virt_devs),
24562443
GFP_KERNEL);
24572444
if (!opp_table->genpd_virt_devs)
2458-
goto unlock;
2445+
return -ENOMEM;
24592446

24602447
while (*name) {
24612448
if (index >= opp_table->required_opp_count) {
@@ -2478,29 +2465,15 @@ static int _opp_attach_genpd(struct opp_table *opp_table, struct device *dev,
24782465

24792466
if (virt_devs)
24802467
*virt_devs = opp_table->genpd_virt_devs;
2481-
mutex_unlock(&opp_table->genpd_virt_dev_lock);
24822468

24832469
return 0;
24842470

24852471
err:
2486-
_detach_genpd(opp_table);
2487-
unlock:
2488-
mutex_unlock(&opp_table->genpd_virt_dev_lock);
2472+
_opp_detach_genpd(opp_table);
24892473
return ret;
24902474

24912475
}
24922476

2493-
static void _opp_detach_genpd(struct opp_table *opp_table)
2494-
{
2495-
/*
2496-
* Acquire genpd_virt_dev_lock to make sure virt_dev isn't getting
2497-
* used in parallel.
2498-
*/
2499-
mutex_lock(&opp_table->genpd_virt_dev_lock);
2500-
_detach_genpd(opp_table);
2501-
mutex_unlock(&opp_table->genpd_virt_dev_lock);
2502-
}
2503-
25042477
static void _opp_clear_config(struct opp_config_data *data)
25052478
{
25062479
if (data->flags & OPP_CONFIG_GENPD)

drivers/opp/opp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ enum opp_table_access {
160160
* @rate_clk_single: Currently configured frequency for single clk.
161161
* @current_opp: Currently configured OPP for the table.
162162
* @suspend_opp: Pointer to OPP to be used during device suspend.
163-
* @genpd_virt_dev_lock: Mutex protecting the genpd virtual device pointers.
164163
* @genpd_virt_devs: List of virtual devices for multiple genpd support.
165164
* @required_opp_tables: List of device OPP tables that are required by OPPs in
166165
* this table.
@@ -212,7 +211,6 @@ struct opp_table {
212211
struct dev_pm_opp *current_opp;
213212
struct dev_pm_opp *suspend_opp;
214213

215-
struct mutex genpd_virt_dev_lock;
216214
struct device **genpd_virt_devs;
217215
struct opp_table **required_opp_tables;
218216
unsigned int required_opp_count;

0 commit comments

Comments
 (0)