[PATCH v4 2/7] OPP: Move refcount and key update for readability in _opp_table_find_key()

From: Krishna Chaitanya Chundru
Date: Wed Aug 20 2025 - 04:32:18 EST


Refactor _opp_table_find_key() to improve readability by moving the
reference count increment and key update inside the match condition block.

Also make the 'assert' check mandatory instead of treating it as optional.

Signed-off-by: Krishna Chaitanya Chundru <krishna.chundru@xxxxxxxxxxxxxxxx>
---
drivers/opp/core.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index a36c3daac39cd0bdd2a1f7e9bad5b92f0c756153..bf49709b8c39271431772924daf0c003b45eec7f 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -544,24 +544,22 @@ static struct dev_pm_opp *_opp_table_find_key(struct opp_table *opp_table,
struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ERANGE);

/* Assert that the requirement is met */
- if (assert && !assert(opp_table, index))
+ if (!assert(opp_table, index))
return ERR_PTR(-EINVAL);

guard(mutex)(&opp_table->lock);

list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
if (temp_opp->available == available) {
- if (compare(&opp, temp_opp, read(temp_opp, index), *key))
+ if (compare(&opp, temp_opp, read(temp_opp, index), *key)) {
+ /* Increment the reference count of OPP */
+ *key = read(opp, index);
+ dev_pm_opp_get(opp);
break;
+ }
}
}

- /* Increment the reference count of OPP */
- if (!IS_ERR(opp)) {
- *key = read(opp, index);
- dev_pm_opp_get(opp);
- }
-
return opp;
}


--
2.34.1