Skip to content

Commit 2cf7a4c

Browse files
committed
clk: qcom: rpmh: Simplify clk_rpmh_bcm_send_cmd()
This function has some duplication in unlocking a mutex and returns in a few different places. Let's use some if statements to consolidate code and make this a bit easier to read. Cc: Bjorn Andersson <[email protected]> CC: Taniya Das <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 8411aa5 commit 2cf7a4c

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

drivers/clk/qcom/clk-rpmh.c

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -259,38 +259,33 @@ static int clk_rpmh_bcm_send_cmd(struct clk_rpmh *c, bool enable)
259259
{
260260
struct tcs_cmd cmd = { 0 };
261261
u32 cmd_state;
262-
int ret;
262+
int ret = 0;
263263

264264
mutex_lock(&rpmh_clk_lock);
265-
266-
cmd_state = 0;
267265
if (enable) {
268266
cmd_state = 1;
269267
if (c->aggr_state)
270268
cmd_state = c->aggr_state;
269+
} else {
270+
cmd_state = 0;
271271
}
272272

273-
if (c->last_sent_aggr_state == cmd_state) {
274-
mutex_unlock(&rpmh_clk_lock);
275-
return 0;
276-
}
277-
278-
cmd.addr = c->res_addr;
279-
cmd.data = BCM_TCS_CMD(1, enable, 0, cmd_state);
273+
if (c->last_sent_aggr_state != cmd_state) {
274+
cmd.addr = c->res_addr;
275+
cmd.data = BCM_TCS_CMD(1, enable, 0, cmd_state);
280276

281-
ret = clk_rpmh_send(c, RPMH_ACTIVE_ONLY_STATE, &cmd, enable);
282-
if (ret) {
283-
dev_err(c->dev, "set active state of %s failed: (%d)\n",
284-
c->res_name, ret);
285-
mutex_unlock(&rpmh_clk_lock);
286-
return ret;
277+
ret = clk_rpmh_send(c, RPMH_ACTIVE_ONLY_STATE, &cmd, enable);
278+
if (ret) {
279+
dev_err(c->dev, "set active state of %s failed: (%d)\n",
280+
c->res_name, ret);
281+
} else {
282+
c->last_sent_aggr_state = cmd_state;
283+
}
287284
}
288285

289-
c->last_sent_aggr_state = cmd_state;
290-
291286
mutex_unlock(&rpmh_clk_lock);
292287

293-
return 0;
288+
return ret;
294289
}
295290

296291
static int clk_rpmh_bcm_prepare(struct clk_hw *hw)

0 commit comments

Comments
 (0)