Skip to content

Commit 26ddbc3

Browse files
jackson-cooperdstgloorious
authored andcommitted
[zep fromtree] LIB: Allow tfm_log_unpriv to handle large strings
Previously, the tfm_log_unpriv implementation dropped strings that could not fit in the 32 byte buffer. Rework the implementation to instead output them directly to the SVC call, without using the buffer. Change-Id: Ib976bef538d7efdf30a64e3a2091ca1ebfd15764 Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com> (cherry picked from commit 8eb243c)
1 parent 8c5aa2b commit 26ddbc3

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/tfm_log_unpriv/src/tfm_log_unpriv.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Arm Limited. All rights reserved.
2+
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
@@ -8,6 +8,7 @@
88
#include <stdarg.h>
99
#include <stdint.h>
1010
#include <stddef.h>
11+
#include <string.h>
1112

1213
#include "tfm_log_unpriv.h"
1314
#include "tfm_hal_sp_logdev.h"
@@ -27,20 +28,22 @@ static void output_buf(const char *buf, uint32_t buf_len)
2728
static void output_string_to_buf(void *priv, const char *str, uint32_t len)
2829
{
2930
struct tfm_log_unpriv_data *data = priv;
30-
uint32_t i;
3131

32-
if (len > LOG_UNPRIV_BUFFER_SIZE) {
33-
/* Not enough space for str */
34-
return;
35-
} else if ((data->buf_pos + len) > LOG_UNPRIV_BUFFER_SIZE) {
32+
if ((data->buf_pos + len) > LOG_UNPRIV_BUFFER_SIZE) {
3633
/* Flush current buffer and re-use */
3734
output_buf(data->buf, data->buf_pos);
3835
data->buf_pos = 0;
39-
}
4036

41-
for (i = 0; i < len; i++) {
42-
data->buf[data->buf_pos++] = *str++;
37+
/* Handle strings larger than buffer with multiple flushes */
38+
for (; len > LOG_UNPRIV_BUFFER_SIZE;
39+
len -= LOG_UNPRIV_BUFFER_SIZE, str += LOG_UNPRIV_BUFFER_SIZE) {
40+
memcpy(data->buf, str, LOG_UNPRIV_BUFFER_SIZE);
41+
output_buf(data->buf, LOG_UNPRIV_BUFFER_SIZE);
42+
}
4343
}
44+
45+
memcpy(data->buf + data->buf_pos, str, len);
46+
data->buf_pos += len;
4447
}
4548

4649
void tfm_log_unpriv(const char *fmt, ...)

0 commit comments

Comments
 (0)