soc: qcom: rpmh: Use __fill_rpmh_msg API during rpmh_write()

Use __fill_rpmh_msg API during rpmh_write(). This allows to
remove duplication of code in error checking, copying commands
and setting message state.

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Signed-off-by: Maulik Shah <mkshah@codeaurora.org>
Link: https://lore.kernel.org/r/1606379490-4052-1-git-send-email-mkshah@codeaurora.org
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Maulik Shah 2020-11-26 14:01:30 +05:30 committed by Bjorn Andersson
parent bfc1b6597f
commit 0924dad5d4

View File

@ -181,8 +181,6 @@ static int __rpmh_write(const struct device *dev, enum rpmh_state state,
struct cache_req *req; struct cache_req *req;
int i; int i;
rpm_msg->msg.state = state;
/* Cache the request in our store and link the payload */ /* Cache the request in our store and link the payload */
for (i = 0; i < rpm_msg->msg.num_cmds; i++) { for (i = 0; i < rpm_msg->msg.num_cmds; i++) {
req = cache_rpm_request(ctrlr, state, &rpm_msg->msg.cmds[i]); req = cache_rpm_request(ctrlr, state, &rpm_msg->msg.cmds[i]);
@ -190,8 +188,6 @@ static int __rpmh_write(const struct device *dev, enum rpmh_state state,
return PTR_ERR(req); return PTR_ERR(req);
} }
rpm_msg->msg.state = state;
if (state == RPMH_ACTIVE_ONLY_STATE) { if (state == RPMH_ACTIVE_ONLY_STATE) {
WARN_ON(irqs_disabled()); WARN_ON(irqs_disabled());
ret = rpmh_rsc_send_data(ctrlr_to_drv(ctrlr), &rpm_msg->msg); ret = rpmh_rsc_send_data(ctrlr_to_drv(ctrlr), &rpm_msg->msg);
@ -268,11 +264,9 @@ int rpmh_write(const struct device *dev, enum rpmh_state state,
DEFINE_RPMH_MSG_ONSTACK(dev, state, &compl, rpm_msg); DEFINE_RPMH_MSG_ONSTACK(dev, state, &compl, rpm_msg);
int ret; int ret;
if (!cmd || !n || n > MAX_RPMH_PAYLOAD) ret = __fill_rpmh_msg(&rpm_msg, state, cmd, n);
return -EINVAL; if (ret)
return ret;
memcpy(rpm_msg.cmd, cmd, n * sizeof(*cmd));
rpm_msg.msg.num_cmds = n;
ret = __rpmh_write(dev, state, &rpm_msg); ret = __rpmh_write(dev, state, &rpm_msg);
if (ret) if (ret)