Skip to content

Commit 8873d1e

Browse files
quic-bjorandeandersson
authored andcommitted
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>
1 parent 59e0910 commit 8873d1e

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

drivers/soc/qcom/qcom_aoss.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,27 +205,33 @@ static bool qmp_message_empty(struct qmp *qmp)
205205
/**
206206
* qmp_send() - send a message to the AOSS
207207
* @qmp: qmp context
208-
* @data: message to be sent
208+
* @fmt: format string for message to be sent
209+
* @...: arguments for the format string
209210
*
210-
* Transmit @data to AOSS and wait for the AOSS to acknowledge the message.
211+
* Transmit message to AOSS and wait for the AOSS to acknowledge the message.
211212
* data must not be longer than the mailbox size. Access is synchronized by
212213
* this implementation.
213214
*
214215
* Return: 0 on success, negative errno on failure
215216
*/
216-
int qmp_send(struct qmp *qmp, const void *data)
217+
int qmp_send(struct qmp *qmp, const char *fmt, ...)
217218
{
218219
char buf[QMP_MSG_LEN];
219220
long time_left;
221+
va_list args;
222+
int len;
220223
int ret;
221224

222-
if (WARN_ON(IS_ERR_OR_NULL(qmp) || !data))
225+
if (WARN_ON(IS_ERR_OR_NULL(qmp) || !fmt))
223226
return -EINVAL;
224227

225-
if (WARN_ON(strlen(data) >= sizeof(buf)))
226-
return -EINVAL;
228+
memset(buf, 0, sizeof(buf));
229+
va_start(args, fmt);
230+
len = vsnprintf(buf, sizeof(buf), fmt, args);
231+
va_end(args);
227232

228-
strscpy_pad(buf, data, sizeof(buf));
233+
if (WARN_ON(len >= sizeof(buf)))
234+
return -EINVAL;
229235

230236
mutex_lock(&qmp->tx_lock);
231237

include/linux/soc/qcom/qcom_aoss.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ struct qmp;
1313

1414
#if IS_ENABLED(CONFIG_QCOM_AOSS_QMP)
1515

16-
int qmp_send(struct qmp *qmp, const void *data);
16+
int qmp_send(struct qmp *qmp, const char *fmt, ...);
1717
struct qmp *qmp_get(struct device *dev);
1818
void qmp_put(struct qmp *qmp);
1919

2020
#else
2121

22-
static inline int qmp_send(struct qmp *qmp, const void *data)
22+
static inline int qmp_send(struct qmp *qmp, const char *fmt, ...)
2323
{
2424
return -ENODEV;
2525
}

0 commit comments

Comments
 (0)