diff options
| author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2026-08-06 13:22:59 +0200 |
|---|---|---|
| committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2026-08-06 13:22:59 +0200 |
| commit | b3828f66f5facd78a02b3a8cc6ffc4137fa9fb76 (patch) | |
| tree | eefdd3b05e793b630fbbbc1c84f81beda7184e82 /drivers | |
| parent | 075b74841bd0065a3bda3440873c747938e69b68 (diff) | |
| parent | 84f05af0975c9f9c8ffee0361d6f7cbb1f289231 (diff) | |
| download | linux-b3828f66f5facd78a02b3a8cc6ffc4137fa9fb76.tar.gz linux-b3828f66f5facd78a02b3a8cc6ffc4137fa9fb76.zip | |
Merge tag 'opp-updates-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm
Pull OPP (Operating Performance Points) updates for 7.3 from Viresh
Kumar:
"- Fix cleanup ordering around scope-based pointers (Gregor Herburger).
- Use clk_get_optional() for optional clocks (Praveen Talari)."
* tag 'opp-updates-7.3' of git://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm:
opp: Use clk_get_optional() to avoid leaving opp_table->clk as an error pointer
OPP: Fix cleanup ordering
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/opp/core.c | 67 |
1 files changed, 29 insertions, 38 deletions
diff --git a/drivers/opp/core.c b/drivers/opp/core.c index ab0b0a2f85a1..cd0e82dae776 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1412,13 +1412,12 @@ static int _set_opp(struct device *dev, struct opp_table *opp_table, */ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq) { + struct opp_table *opp_table __free(put_opp_table) = + _find_opp_table(dev); struct dev_pm_opp *opp __free(put_opp) = NULL; unsigned long freq = 0, temp_freq; bool forced = false; - struct opp_table *opp_table __free(put_opp_table) = - _find_opp_table(dev); - if (IS_ERR(opp_table)) { dev_err(dev, "%s: device's opp table doesn't exist\n", __func__); return PTR_ERR(opp_table); @@ -1582,8 +1581,6 @@ static struct opp_table *_update_opp_table_clk(struct device *dev, struct opp_table *opp_table, bool getclk) { - int ret; - /* * Return early if we don't need to get clk or we have already done it * earlier. @@ -1592,39 +1589,35 @@ static struct opp_table *_update_opp_table_clk(struct device *dev, opp_table->clks) return opp_table; - /* Find clk for the device */ - opp_table->clk = clk_get(dev, NULL); + /* + * There are few platforms which don't want the OPP core to manage + * device's clock settings. In such cases neither the platform + * provides the clks explicitly to us, nor the DT contains a valid + * clk entry. The OPP nodes in DT may still contain "opp-hz" property + * though, which we need to parse and allow the platform to find an + * OPP based on freq later on. + * + * This is a simple solution to take care of such corner cases, i.e. + * make the clk_count 1, which lets us allocate space for frequency + * in opp->rates and also parse the entries in DT. Use + * clk_get_optional() instead of clk_get() so opp_table->clk stays + * NULL for such devices, instead of holding an ERR_PTR(-ENOENT) that + * consumers must remember to special-case. + */ + opp_table->clk = clk_get_optional(dev, NULL); - ret = PTR_ERR_OR_ZERO(opp_table->clk); - if (!ret) { - opp_table->config_clks = _opp_config_clk_single; - opp_table->clk_count = 1; - return opp_table; + if (IS_ERR(opp_table->clk)) { + dev_pm_opp_put_opp_table(opp_table); + dev_err_probe(dev, PTR_ERR(opp_table->clk), "Couldn't find clock\n"); + return ERR_CAST(opp_table->clk); } - if (ret == -ENOENT) { - /* - * There are few platforms which don't want the OPP core to - * manage device's clock settings. In such cases neither the - * platform provides the clks explicitly to us, nor the DT - * contains a valid clk entry. The OPP nodes in DT may still - * contain "opp-hz" property though, which we need to parse and - * allow the platform to find an OPP based on freq later on. - * - * This is a simple solution to take care of such corner cases, - * i.e. make the clk_count 1, which lets us allocate space for - * frequency in opp->rates and also parse the entries in DT. - */ - opp_table->clk_count = 1; - - dev_dbg(dev, "%s: Couldn't find clock: %d\n", __func__, ret); - return opp_table; - } + if (opp_table->clk) + opp_table->config_clks = _opp_config_clk_single; - dev_pm_opp_put_opp_table(opp_table); - dev_err_probe(dev, ret, "Couldn't find clock\n"); + opp_table->clk_count = 1; - return ERR_PTR(ret); + return opp_table; } /* @@ -2870,11 +2863,10 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_add_dynamic); static int _opp_set_availability(struct device *dev, unsigned long freq, bool availability_req) { - struct dev_pm_opp *opp __free(put_opp) = ERR_PTR(-ENODEV), *tmp_opp; - /* Find the opp_table */ struct opp_table *opp_table __free(put_opp_table) = _find_opp_table(dev); + struct dev_pm_opp *opp __free(put_opp) = ERR_PTR(-ENODEV), *tmp_opp; if (IS_ERR(opp_table)) { dev_warn(dev, "%s: Device OPP not found (%ld)\n", __func__, @@ -2932,12 +2924,11 @@ int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq, unsigned long u_volt_max) { - struct dev_pm_opp *opp __free(put_opp) = ERR_PTR(-ENODEV), *tmp_opp; - int r; - /* Find the opp_table */ struct opp_table *opp_table __free(put_opp_table) = _find_opp_table(dev); + struct dev_pm_opp *opp __free(put_opp) = ERR_PTR(-ENODEV), *tmp_opp; + int r; if (IS_ERR(opp_table)) { r = PTR_ERR(opp_table); |
