Merge branches 'pm-devfreq' and 'pm-opp'

Merge devfreq and OPP (Operating Performance Points) updates for 6.14:

 - Clean up the Exynos devfreq driver and devfreq core (Markus Elfring,
   Jeongjun Park).

 - Minor cleanups and fixes for OPP (Dan Carpenter, Neil Armstrong, Joe
   Hattori).

 - Implement dev_pm_opp_get_bw() (Neil Armstrong).

 - Expose OPP reference counting helpers for Rust (Viresh Kumar).

* pm-devfreq:
  PM / devfreq: exynos: remove unused function parameter
  PM / devfreq: event: Call of_node_put() only once in devfreq_event_get_edev_by_phandle()

* pm-opp:
  PM / OPP: Add reference counting helpers for Rust implementation
  OPP: OF: Fix an OF node leak in _opp_add_static_v2()
  OPP: fix dev_pm_opp_find_bw_*() when bandwidth table not initialized
  OPP: add index check to assert to avoid buffer overflow in _read_freq()
  opp: core: Fix off by one in dev_pm_opp_get_bw()
  opp: core: implement dev_pm_opp_get_bw
pull/1131/head
Rafael J. Wysocki 2025-01-20 20:56:33 +01:00
commit eddd3769eb
6 changed files with 97 additions and 33 deletions

View File

@ -244,13 +244,9 @@ struct devfreq_event_dev *devfreq_event_get_edev_by_phandle(struct device *dev,
edev = NULL;
out:
mutex_unlock(&devfreq_event_list_lock);
if (!edev) {
of_node_put(node);
return ERR_PTR(-ENODEV);
}
of_node_put(node);
if (!edev)
return ERR_PTR(-ENODEV);
return edev;
}

View File

@ -236,8 +236,7 @@ err_regulator:
return ret;
}
static int exynos_bus_parse_of(struct device_node *np,
struct exynos_bus *bus)
static int exynos_bus_parse_of(struct exynos_bus *bus)
{
struct device *dev = bus->dev;
struct dev_pm_opp *opp;
@ -408,7 +407,7 @@ static int exynos_bus_probe(struct platform_device *pdev)
}
/* Parse the device-tree to get the resource information */
ret = exynos_bus_parse_of(np, bus);
ret = exynos_bus_parse_of(bus);
if (ret < 0)
goto err_reg;

View File

@ -101,11 +101,55 @@ struct opp_table *_find_opp_table(struct device *dev)
* representation in the OPP table and manage the clock configuration themselves
* in an platform specific way.
*/
static bool assert_single_clk(struct opp_table *opp_table)
static bool assert_single_clk(struct opp_table *opp_table,
unsigned int __always_unused index)
{
return !WARN_ON(opp_table->clk_count > 1);
}
/*
* Returns true if clock table is large enough to contain the clock index.
*/
static bool assert_clk_index(struct opp_table *opp_table,
unsigned int index)
{
return opp_table->clk_count > index;
}
/*
* Returns true if bandwidth table is large enough to contain the bandwidth index.
*/
static bool assert_bandwidth_index(struct opp_table *opp_table,
unsigned int index)
{
return opp_table->path_count > index;
}
/**
* dev_pm_opp_get_bw() - Gets the bandwidth corresponding to an opp
* @opp: opp for which bandwidth has to be returned for
* @peak: select peak or average bandwidth
* @index: bandwidth index
*
* Return: bandwidth in kBps, else return 0
*/
unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index)
{
if (IS_ERR_OR_NULL(opp)) {
pr_err("%s: Invalid parameters\n", __func__);
return 0;
}
if (index >= opp->opp_table->path_count)
return 0;
if (!opp->bandwidth)
return 0;
return peak ? opp->bandwidth[index].peak : opp->bandwidth[index].avg;
}
EXPORT_SYMBOL_GPL(dev_pm_opp_get_bw);
/**
* dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
* @opp: opp for which voltage has to be returned for
@ -499,12 +543,12 @@ static struct dev_pm_opp *_opp_table_find_key(struct opp_table *opp_table,
unsigned long (*read)(struct dev_pm_opp *opp, int index),
bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp,
unsigned long opp_key, unsigned long key),
bool (*assert)(struct opp_table *opp_table))
bool (*assert)(struct opp_table *opp_table, unsigned int index))
{
struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);
/* Assert that the requirement is met */
if (assert && !assert(opp_table))
if (assert && !assert(opp_table, index))
return ERR_PTR(-EINVAL);
mutex_lock(&opp_table->lock);
@ -532,7 +576,7 @@ _find_key(struct device *dev, unsigned long *key, int index, bool available,
unsigned long (*read)(struct dev_pm_opp *opp, int index),
bool (*compare)(struct dev_pm_opp **opp, struct dev_pm_opp *temp_opp,
unsigned long opp_key, unsigned long key),
bool (*assert)(struct opp_table *opp_table))
bool (*assert)(struct opp_table *opp_table, unsigned int index))
{
struct opp_table *opp_table;
struct dev_pm_opp *opp;
@ -555,7 +599,7 @@ _find_key(struct device *dev, unsigned long *key, int index, bool available,
static struct dev_pm_opp *_find_key_exact(struct device *dev,
unsigned long key, int index, bool available,
unsigned long (*read)(struct dev_pm_opp *opp, int index),
bool (*assert)(struct opp_table *opp_table))
bool (*assert)(struct opp_table *opp_table, unsigned int index))
{
/*
* The value of key will be updated here, but will be ignored as the
@ -568,7 +612,7 @@ static struct dev_pm_opp *_find_key_exact(struct device *dev,
static struct dev_pm_opp *_opp_table_find_key_ceil(struct opp_table *opp_table,
unsigned long *key, int index, bool available,
unsigned long (*read)(struct dev_pm_opp *opp, int index),
bool (*assert)(struct opp_table *opp_table))
bool (*assert)(struct opp_table *opp_table, unsigned int index))
{
return _opp_table_find_key(opp_table, key, index, available, read,
_compare_ceil, assert);
@ -577,7 +621,7 @@ static struct dev_pm_opp *_opp_table_find_key_ceil(struct opp_table *opp_table,
static struct dev_pm_opp *_find_key_ceil(struct device *dev, unsigned long *key,
int index, bool available,
unsigned long (*read)(struct dev_pm_opp *opp, int index),
bool (*assert)(struct opp_table *opp_table))
bool (*assert)(struct opp_table *opp_table, unsigned int index))
{
return _find_key(dev, key, index, available, read, _compare_ceil,
assert);
@ -586,7 +630,7 @@ static struct dev_pm_opp *_find_key_ceil(struct device *dev, unsigned long *key,
static struct dev_pm_opp *_find_key_floor(struct device *dev,
unsigned long *key, int index, bool available,
unsigned long (*read)(struct dev_pm_opp *opp, int index),
bool (*assert)(struct opp_table *opp_table))
bool (*assert)(struct opp_table *opp_table, unsigned int index))
{
return _find_key(dev, key, index, available, read, _compare_floor,
assert);
@ -647,7 +691,8 @@ struct dev_pm_opp *
dev_pm_opp_find_freq_exact_indexed(struct device *dev, unsigned long freq,
u32 index, bool available)
{
return _find_key_exact(dev, freq, index, available, _read_freq, NULL);
return _find_key_exact(dev, freq, index, available, _read_freq,
assert_clk_index);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_exact_indexed);
@ -707,7 +752,8 @@ struct dev_pm_opp *
dev_pm_opp_find_freq_ceil_indexed(struct device *dev, unsigned long *freq,
u32 index)
{
return _find_key_ceil(dev, freq, index, true, _read_freq, NULL);
return _find_key_ceil(dev, freq, index, true, _read_freq,
assert_clk_index);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil_indexed);
@ -760,7 +806,7 @@ struct dev_pm_opp *
dev_pm_opp_find_freq_floor_indexed(struct device *dev, unsigned long *freq,
u32 index)
{
return _find_key_floor(dev, freq, index, true, _read_freq, NULL);
return _find_key_floor(dev, freq, index, true, _read_freq, assert_clk_index);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor_indexed);
@ -878,7 +924,8 @@ struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev, unsigned int *bw,
unsigned long temp = *bw;
struct dev_pm_opp *opp;
opp = _find_key_ceil(dev, &temp, index, true, _read_bw, NULL);
opp = _find_key_ceil(dev, &temp, index, true, _read_bw,
assert_bandwidth_index);
*bw = temp;
return opp;
}
@ -909,7 +956,8 @@ struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
unsigned long temp = *bw;
struct dev_pm_opp *opp;
opp = _find_key_floor(dev, &temp, index, true, _read_bw, NULL);
opp = _find_key_floor(dev, &temp, index, true, _read_bw,
assert_bandwidth_index);
*bw = temp;
return opp;
}
@ -1480,11 +1528,6 @@ err:
return ERR_PTR(ret);
}
void _get_opp_table_kref(struct opp_table *opp_table)
{
kref_get(&opp_table->kref);
}
static struct opp_table *_update_opp_table_clk(struct device *dev,
struct opp_table *opp_table,
bool getclk)
@ -1645,6 +1688,17 @@ static void _opp_table_kref_release(struct kref *kref)
kfree(opp_table);
}
void _get_opp_table_kref(struct opp_table *opp_table)
{
kref_get(&opp_table->kref);
}
void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table)
{
_get_opp_table_kref(opp_table);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_table_ref);
void dev_pm_opp_put_opp_table(struct opp_table *opp_table)
{
kref_put_mutex(&opp_table->kref, _opp_table_kref_release,
@ -1679,6 +1733,7 @@ void dev_pm_opp_get(struct dev_pm_opp *opp)
{
kref_get(&opp->kref);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_get);
void dev_pm_opp_put(struct dev_pm_opp *opp)
{
@ -1702,7 +1757,7 @@ void dev_pm_opp_remove(struct device *dev, unsigned long freq)
if (IS_ERR(opp_table))
return;
if (!assert_single_clk(opp_table))
if (!assert_single_clk(opp_table, 0))
goto put_table;
mutex_lock(&opp_table->lock);
@ -2054,7 +2109,7 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
unsigned long tol, u_volt = data->u_volt;
int ret;
if (!assert_single_clk(opp_table))
if (!assert_single_clk(opp_table, 0))
return -EINVAL;
new_opp = _opp_allocate(opp_table);
@ -2810,7 +2865,7 @@ static int _opp_set_availability(struct device *dev, unsigned long freq,
return r;
}
if (!assert_single_clk(opp_table)) {
if (!assert_single_clk(opp_table, 0)) {
r = -EINVAL;
goto put_table;
}
@ -2886,7 +2941,7 @@ int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
return r;
}
if (!assert_single_clk(opp_table)) {
if (!assert_single_clk(opp_table, 0)) {
r = -EINVAL;
goto put_table;
}

View File

@ -926,7 +926,7 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,
ret = _of_opp_alloc_required_opps(opp_table, new_opp);
if (ret)
goto free_opp;
goto put_node;
if (!of_property_read_u32(np, "clock-latency-ns", &val))
new_opp->clock_latency_ns = val;
@ -976,6 +976,8 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,
free_required_opps:
_of_opp_free_required_opps(opp_table, new_opp);
put_node:
of_node_put(np);
free_opp:
_opp_free(new_opp);

View File

@ -250,7 +250,6 @@ struct opp_table {
};
/* Routines internal to opp core */
void dev_pm_opp_get(struct dev_pm_opp *opp);
bool _opp_remove_all_static(struct opp_table *opp_table);
void _get_opp_table_kref(struct opp_table *opp_table);
int _get_opp_count(struct opp_table *opp_table);

View File

@ -100,8 +100,11 @@ struct dev_pm_opp_data {
#if defined(CONFIG_PM_OPP)
struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table);
void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index);
unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies);
@ -158,6 +161,7 @@ struct dev_pm_opp *dev_pm_opp_find_bw_ceil(struct device *dev,
struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
unsigned int *bw, int index);
void dev_pm_opp_get(struct dev_pm_opp *opp);
void dev_pm_opp_put(struct dev_pm_opp *opp);
int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp);
@ -203,8 +207,15 @@ static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *
return ERR_PTR(-EOPNOTSUPP);
}
static inline void dev_pm_opp_get_opp_table_ref(struct opp_table *opp_table) {}
static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
static inline unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index)
{
return 0;
}
static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
{
return 0;
@ -334,6 +345,8 @@ static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
return ERR_PTR(-EOPNOTSUPP);
}
static inline void dev_pm_opp_get(struct dev_pm_opp *opp) {}
static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
static inline int