Skip to content

Commit c229f8f

Browse files
povikmarcan
authored andcommitted
soc: apple: rtkit: Crop syslog messages
Crop trailing whitespace, null, and newline characters in syslog messages received from coprocessors. Notably DCP sends its messages including a trailing newline, so prior to this change we would end up cluttering the kernel log by repeated newlines at the end of messages. Signed-off-by: Martin Povišer <[email protected]> Reviewed-by: Hector Martin <[email protected]> Signed-off-by: Hector Martin <[email protected]>
1 parent 1ad28c1 commit c229f8f

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

drivers/soc/apple/rtkit.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,17 @@ static void apple_rtkit_syslog_rx_init(struct apple_rtkit *rtk, u64 msg)
416416
rtk->syslog_n_entries, rtk->syslog_msg_size);
417417
}
418418

419+
static bool should_crop_syslog_char(char c)
420+
{
421+
return c == '\n' || c == '\r' || c == ' ' || c == '\0';
422+
}
423+
419424
static void apple_rtkit_syslog_rx_log(struct apple_rtkit *rtk, u64 msg)
420425
{
421426
u8 idx = msg & 0xff;
422427
char log_context[24];
423428
size_t entry_size = 0x20 + rtk->syslog_msg_size;
429+
int msglen;
424430

425431
if (!rtk->syslog_msg_buffer) {
426432
dev_warn(
@@ -453,7 +459,13 @@ static void apple_rtkit_syslog_rx_log(struct apple_rtkit *rtk, u64 msg)
453459
rtk->syslog_msg_size);
454460

455461
log_context[sizeof(log_context) - 1] = 0;
456-
rtk->syslog_msg_buffer[rtk->syslog_msg_size - 1] = 0;
462+
463+
msglen = rtk->syslog_msg_size - 1;
464+
while (msglen > 0 &&
465+
should_crop_syslog_char(rtk->syslog_msg_buffer[msglen - 1]))
466+
msglen--;
467+
468+
rtk->syslog_msg_buffer[msglen] = 0;
457469
dev_info(rtk->dev, "RTKit: syslog message: %s: %s\n", log_context,
458470
rtk->syslog_msg_buffer);
459471

0 commit comments

Comments
 (0)