From patchwork Fri Feb 24 16:21:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Povi=C5=A1er?= X-Patchwork-Id: 13151486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0CC2AC7EE23 for ; Fri, 24 Feb 2023 16:23:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=2Mn6jSAij43RJNFQFopkchEVkOi+yyucXlWLOE4fOmA=; b=I9s+k3DA1JaG/T YyHC0ZWaUbG67njeuuImh0ZfyCF/oUtueKppAIPI0YxVtG0Jwg4itGIHCTIs+zsXC82OC4tEWng6k inWtmCjr3b3JSEqkehx7VkaYMC6XL1yBG55G6dW3ThKvHF/hU2zRPsLXooDNMMigm2S1+clrLz4Sf foHuxE/u2rbhLAX3ELBD2K2IFL2RMEmxESwMFLdVOwgcwiA1LBLXhEZ8YfkJ3QMcXZ8IMxYYstI1+ W+WHseF0sdJ+lJCLZhuRiy4VppTUgHifqVf+AaevmIQmk6556epQDt8V83d3Ubacf8j5kCxjgBcFC yEqGEmrCWZ4a01ExdCWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pVapk-0036DH-L1; Fri, 24 Feb 2023 16:22:08 +0000 Received: from [2a03:3b40:fe:f0::1] (helo=hutie.ust.cz) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pVapg-0036Bp-Cs for linux-arm-kernel@lists.infradead.org; Fri, 24 Feb 2023 16:22:06 +0000 From: =?utf-8?q?Martin_Povi=C5=A1er?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cutebit.org; s=mail; t=1677255722; bh=5doeosS9EHjVo4INuIYpNqv+kkFiPbeHbMYZHjoGVWM=; h=From:To:Cc:Subject:Date; b=G8ZShmzQ+zrOvl6A66hdsEM7QQBjCPXjk1zWtDJaDT8gF3BVhGVnR6C3HfcxhjbeJ AWCsjd7GvztCq8pMIfE5F5nN/EgBJgRDJfSBHW+ySkqU09iBnihIg6FlbjgFHmwtRN aHG1X9lB98Yeds3fsNOurHa40DgtwZ5ptNq7OKfA= To: Hector Martin , Sven Peter Cc: Alyssa Rosenzweig , asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?q?Martin_Povi=C5=A1er?= Subject: [PATCH] soc: apple: rtkit: Crop syslog messages Date: Fri, 24 Feb 2023 17:21:59 +0100 Message-Id: <20230224162159.46348-1-povik+lin@cutebit.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230224_082205_497955_F1E417E6 X-CRM114-Status: UNSURE ( 9.74 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 Reviewed-by: Hector Martin --- drivers/soc/apple/rtkit.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 35ec35aa500d..639f5134d159 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -409,11 +409,17 @@ static void apple_rtkit_syslog_rx_init(struct apple_rtkit *rtk, u64 msg) rtk->syslog_n_entries, rtk->syslog_msg_size); } +static bool should_crop_syslog_char(char c) +{ + return c == '\n' || c == '\r' || c == ' ' || c == '\0'; +} + static void apple_rtkit_syslog_rx_log(struct apple_rtkit *rtk, u64 msg) { u8 idx = msg & 0xff; char log_context[24]; size_t entry_size = 0x20 + rtk->syslog_msg_size; + int msglen; if (!rtk->syslog_msg_buffer) { dev_warn( @@ -446,7 +452,13 @@ static void apple_rtkit_syslog_rx_log(struct apple_rtkit *rtk, u64 msg) rtk->syslog_msg_size); log_context[sizeof(log_context) - 1] = 0; - rtk->syslog_msg_buffer[rtk->syslog_msg_size - 1] = 0; + + msglen = rtk->syslog_msg_size - 1; + while (msglen > 0 && + should_crop_syslog_char(rtk->syslog_msg_buffer[msglen - 1])) + msglen--; + + rtk->syslog_msg_buffer[msglen] = 0; dev_info(rtk->dev, "RTKit: syslog message: %s: %s\n", log_context, rtk->syslog_msg_buffer);