Skip to content

Commit 5f43c12

Browse files
ch-perrypathakraul
authored andcommitted
lib: clock: refactor __rpmi_clock_set_state
There's no need for a special case for clocks with no child in the disable path and no parent in the enable path. Since childs/parents must be checked/enabled before taking care of the clock of interest in any case, some code duplication and a goto can be eliminated. Signed-off-by: Charles Perry <charles.perry@microchip.com>
1 parent bd15a09 commit 5f43c12

1 file changed

Lines changed: 10 additions & 30 deletions

File tree

lib/rpmi_service_group_clock.c

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,14 @@ static enum rpmi_error __rpmi_clock_set_state(struct rpmi_clock_group *clkgrp,
202202
if (clk->current_state == RPMI_CLK_STATE_DISABLED) {
203203
return RPMI_SUCCESS;
204204
}
205-
/* If the clock has no child or its a parent with single enable
206-
* count then - disable, update cache and return */
207-
if (!clk->child_count || clk->enable_count == 1) {
208-
ret = clkgrp->ops->set_state(clkgrp->ops_priv,
209-
clk->id, state);
210-
if (ret)
211-
return ret;
212-
213-
clk->current_state = state;
214-
clk->enable_count -= 1;
215-
goto done;
216-
}
217205

218206
/* Check if all child clocks are disabled, otherwise deny */
219-
rpmi_list_for_each(pos, &clk->child_clock) {
220-
struct rpmi_clock *cc = to_rpmi_clock(pos);
221-
if (cc->current_state == RPMI_CLK_STATE_ENABLED)
222-
return RPMI_ERR_DENIED;
207+
if (clk->child_count) {
208+
rpmi_list_for_each(pos, &clk->child_clock) {
209+
struct rpmi_clock *cc = to_rpmi_clock(pos);
210+
if (cc->current_state == RPMI_CLK_STATE_ENABLED)
211+
return RPMI_ERR_DENIED;
212+
}
223213
}
224214

225215
ret = clkgrp->ops->set_state(clkgrp->ops_priv, clk->id, state);
@@ -238,22 +228,13 @@ static enum rpmi_error __rpmi_clock_set_state(struct rpmi_clock_group *clkgrp,
238228
if (clk->current_state == RPMI_CLK_STATE_ENABLED)
239229
return RPMI_SUCCESS;
240230

241-
if (!clk->parent) {
242-
ret = clkgrp->ops->set_state(clkgrp->ops_priv,
243-
clk->id, state);
244-
if (ret)
231+
/* Enable all parents recursively up to the root */
232+
if (clk->parent) {
233+
ret = __rpmi_clock_set_state(clkgrp, clk->parent, state);
234+
if (ret && ret != RPMI_ERR_ALREADY)
245235
return ret;
246-
247-
clk->current_state = state;
248-
clk->enable_count += 1;
249-
goto done;
250236
}
251237

252-
/* Enable all parents recursively up to the root */
253-
ret = __rpmi_clock_set_state(clkgrp, clk->parent, state);
254-
if (ret && ret != RPMI_ERR_ALREADY)
255-
return ret;
256-
257238
ret = clkgrp->ops->set_state(clkgrp->ops_priv, clk->id, state);
258239
if (ret)
259240
return ret;
@@ -262,7 +243,6 @@ static enum rpmi_error __rpmi_clock_set_state(struct rpmi_clock_group *clkgrp,
262243
clk->enable_count += 1;
263244
}
264245

265-
done:
266246
return RPMI_SUCCESS;
267247
}
268248

0 commit comments

Comments
 (0)