summaryrefslogtreecommitdiff
path: root/drivers/soc
diff options
context:
space:
mode:
authorBjorn Andersson <quic_bjorande@quicinc.com>2023-08-11 13:58:38 -0700
committerBjorn Andersson <andersson@kernel.org>2023-08-13 19:27:32 -0700
commit8873d1e2f88afbe89c99d8f49f88934a2da2991f (patch)
tree6d8fe660174a0ab1c7c26662e7315ad77481085b /drivers/soc
parent59e09100836fdb618b107c37189d6001b5825872 (diff)
soc: qcom: aoss: Format string in qmp_send()
The majority of callers to qmp_send() composes the message dynamically using some form of sprintf(), resulting in unnecessary complication and stack usage. By changing the interface of qmp_send() to take a format string and arguments, the duplicated composition of the commands can be moved to a single location. Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org> Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com> Link: https://lore.kernel.org/r/20230811205839.727373-4-quic_bjorande@quicinc.com Signed-off-by: Bjorn Andersson <andersson@kernel.org>
Diffstat (limited to 'drivers/soc')
-rw-r--r--drivers/soc/qcom/qcom_aoss.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/drivers/soc/qcom/qcom_aoss.c b/drivers/soc/qcom/qcom_aoss.c
index 880fe234ca0a..8424d1da4db9 100644
--- a/drivers/soc/qcom/qcom_aoss.c
+++ b/drivers/soc/qcom/qcom_aoss.c
@@ -205,27 +205,33 @@ static bool qmp_message_empty(struct qmp *qmp)
/**
* qmp_send() - send a message to the AOSS
* @qmp: qmp context
- * @data: message to be sent
+ * @fmt: format string for message to be sent
+ * @...: arguments for the format string
*
- * Transmit @data to AOSS and wait for the AOSS to acknowledge the message.
+ * Transmit message to AOSS and wait for the AOSS to acknowledge the message.
* data must not be longer than the mailbox size. Access is synchronized by
* this implementation.
*
* Return: 0 on success, negative errno on failure
*/
-int qmp_send(struct qmp *qmp, const void *data)
+int qmp_send(struct qmp *qmp, const char *fmt, ...)
{
char buf[QMP_MSG_LEN];
long time_left;
+ va_list args;
+ int len;
int ret;
- if (WARN_ON(IS_ERR_OR_NULL(qmp) || !data))
+ if (WARN_ON(IS_ERR_OR_NULL(qmp) || !fmt))
return -EINVAL;
- if (WARN_ON(strlen(data) >= sizeof(buf)))
- return -EINVAL;
+ memset(buf, 0, sizeof(buf));
+ va_start(args, fmt);
+ len = vsnprintf(buf, sizeof(buf), fmt, args);
+ va_end(args);
- strscpy_pad(buf, data, sizeof(buf));
+ if (WARN_ON(len >= sizeof(buf)))
+ return -EINVAL;
mutex_lock(&qmp->tx_lock);