lkml.org 
[lkml]   [2022]   [Jun]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 7/8] OPP: Assert clk_count == 1 for single clk helpers
Date
Many helpers can be safely called only for devices that have a single
clk associated with them. Assert the same for those routines.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/opp/core.c | 39 +++++++++++++++++++++++++++++++++------
1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index b8e6dc0a9b36..5635f4ad6d59 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -93,6 +93,12 @@ struct opp_table *_find_opp_table(struct device *dev)
return opp_table;
}

+/* Returns true for single clock, false with WARN otherwise */
+bool assert_single_clk(struct opp_table *opp_table)
+{
+ return !WARN_ON(opp_table->clk_count != 1);
+}
+
/**
* dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
* @opp: opp for which voltage has to be returned for
@@ -177,6 +183,9 @@ unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
return 0;
}

+ if (!assert_single_clk(opp->opp_table))
+ return 0;
+
return opp->rates[0];
}
EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq);
@@ -597,7 +606,8 @@ static struct dev_pm_opp *_find_key_floor(struct device *dev,
struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
unsigned long freq, bool available)
{
- return _find_key_exact(dev, freq, 0, available, _read_freq, NULL);
+ return _find_key_exact(dev, freq, 0, available, _read_freq,
+ assert_single_clk);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact);

@@ -605,7 +615,7 @@ static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
unsigned long *freq)
{
return _opp_table_find_key_ceil(opp_table, freq, 0, true, _read_freq,
- NULL);
+ assert_single_clk);
}

/**
@@ -629,7 +639,7 @@ static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
unsigned long *freq)
{
- return _find_key_ceil(dev, freq, 0, true, _read_freq, NULL);
+ return _find_key_ceil(dev, freq, 0, true, _read_freq, assert_single_clk);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);

@@ -654,7 +664,7 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);
struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
unsigned long *freq)
{
- return _find_key_floor(dev, freq, 0, true, _read_freq, NULL);
+ return _find_key_floor(dev, freq, 0, true, _read_freq, assert_single_clk);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor);

@@ -1507,6 +1517,9 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq)
if (IS_ERR(opp_table))
return;

+ if (!assert_single_clk(opp_table))
+ goto put_table;
+
mutex_lock(&opp_table->lock);

list_for_each_entry(iter, &opp_table->opp_list, node) {
@@ -1528,6 +1541,7 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq)
__func__, freq);
}

+put_table:
/* Drop the reference taken by _find_opp_table() */
dev_pm_opp_put_opp_table(opp_table);
}
@@ -1819,6 +1833,9 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
unsigned long tol;
int ret;

+ if (!assert_single_clk(opp_table))
+ return -EINVAL;
+
new_opp = _opp_allocate(opp_table);
if (!new_opp)
return -ENOMEM;
@@ -2600,6 +2617,11 @@ static int _opp_set_availability(struct device *dev, unsigned long freq,
return r;
}

+ if (!assert_single_clk(opp_table)) {
+ r = -EINVAL;
+ goto put_table;
+ }
+
mutex_lock(&opp_table->lock);

/* Do we have the frequency? */
@@ -2671,6 +2693,11 @@ int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
return r;
}

+ if (!assert_single_clk(opp_table)) {
+ r = -EINVAL;
+ goto put_table;
+ }
+
mutex_lock(&opp_table->lock);

/* Do we have the frequency? */
@@ -2702,11 +2729,11 @@ int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
opp);

dev_pm_opp_put(opp);
- goto adjust_put_table;
+ goto put_table;

adjust_unlock:
mutex_unlock(&opp_table->lock);
-adjust_put_table:
+put_table:
dev_pm_opp_put_opp_table(opp_table);
return r;
}
--
2.31.1.272.g89b43f80a514
\
 
 \ /
  Last update: 2022-06-10 10:26    [W:0.273 / U:0.308 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site