From 4033df202b20e77a0c2bc913467c29fad9e2b311 Mon Sep 17 00:00:00 2001 From: "Isaac J. Manjarres" Date: Mon, 3 Feb 2025 17:21:21 -0800 Subject: [PATCH] ANDROID: OPP: Fix incorrectly backported logic in _set_opp_level() Commit b50a013d3317 ("BACKPORT: OPP: Extend support for the opp-level beyond required-opps") used dev_pm_genpd_set_performance_state() as a substitute for dev_pm_domain_set_performance_state(), since introducing dev_pm_domain_set_performance_state() required breaking the ABI on this branch. However, directly invoking dev_pm_genpd_set_performance_state() is not equivalent to dev_pm_domain_set_performance_state(), as the latter only invokes a PM domain's set_performance_state callback if the device it is invoked on uses a PM domain, and if that PM domain supports that callback. If that check fails, then the invocation is simply a nop, and no error code is returned. In contrast, dev_pm_genpd_set_performance_state() checks to ensure that the device uses a PM domain, and that the PM domain is a generic PM domain. If that is not the case, then the invocation returns an error which is then propagated up the call chain. Therefore, fix _set_opp_level() to function as a nop for devices without PM domains to align it to its original intent. Bug: 394178898 Fixes: b50a013d3317 ("BACKPORT: OPP: Extend support for the opp-level beyond required-opps") Change-Id: I664d45168404d62aecf59a0afcd2e001d6b7a247 Signed-off-by: Isaac J. Manjarres --- drivers/opp/core.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 5dd9ae2f3489..37702dc41532 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1024,11 +1024,18 @@ static int _set_opp_level(struct device *dev, struct opp_table *opp_table, level = opp->level; } - /* Request a new performance state through the device's PM domain. */ - ret = dev_pm_genpd_set_performance_state(dev, level); - if (ret) - dev_err(dev, "Failed to set performance state %u (%d)\n", level, - ret); + /* + * This function should be a nop for devices without a PM domain. However, + * dev_pm_genpd_set_performance_state() returns an error for devices without a PM domain + * instead of returning immediately. + */ + if (dev->pm_domain) { + /* Request a new performance state through the device's PM domain. */ + ret = dev_pm_genpd_set_performance_state(dev, level); + if (ret) + dev_err(dev, "Failed to set performance state %u (%d)\n", level, + ret); + } return ret; }