Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4920567pxu; Thu, 10 Dec 2020 08:31:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxTuhFkx3vrANT+xxxU3zx5QZimEuqWtUWts/2a8iKdKSCfjlfHBI6bC+bJW4JEcfhCIkZi X-Received: by 2002:a05:6402:31b5:: with SMTP id dj21mr7795767edb.90.1607617919449; Thu, 10 Dec 2020 08:31:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607617919; cv=none; d=google.com; s=arc-20160816; b=Zte3Xh/Z/ZicnjeQweMIeif7Bo5RYvg11bASoL/eGXxBJH6JuU1zUfDsfUvm8enkgY rCO/8Mm/Udm9a1MsmQLCL5VsjbVGif0JRolNpOXF+nPqSDbU4ohSlXL6QCNsKDVigI0x aQV9ZwmPV+xRfkJWl0JqkNaiXlkwuKCTAfijDSlt95le4S08SSjGkSgPP+1Ria9q8IuG nsBj3hmcevo1ZOB0tsVidW0x/GfZloG21LbqS16ne8VGmCiZPXUKxnVy2aRv7L1PLcXo T/OS90NShmAYOU5/MJHyTe1Z8OeJhaztK3mUcdlq6CJM70DExAt3eQmUF+sbC00ltlwP WUBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=N1n4I9waNd4LCTrERpUvVDupIZNujfoQq5lAZ0KQErQ=; b=Ou1Wkqo/1M9a8eIio4Tgug44GKdvhqqy16nRTkRU637HdIlS22hC9nb/znb+tsdzhm tN/pUp+L/uoErp/SLTo1qIa9h5lhwRbdlP0YWO/QhFSDhKp3mz/6ZHFKeBNXzq1cB6k5 GKfLHw9or1UBelH7sAUtYDAkC6XunikXqxPupIbi8wm/7bW4DSxw2BEgiDQiRPskdR/A Q9Km+686W1lgFAiatq+wjnd9M1h0QRioE2swZNQphYhjmMvXA6pl9MM7lOJsELxBBnjb eTew/alrAY7M/eZDQZBCnKgaipLElDIwm3PHCok4pz0ikoZJtJb0rYXQqR0D5CdzfexN ukkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j24si2735638ejt.651.2020.12.10.08.31.34; Thu, 10 Dec 2020 08:31:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391188AbgLJQ3V (ORCPT + 99 others); Thu, 10 Dec 2020 11:29:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:34586 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388492AbgLJQFd (ORCPT ); Thu, 10 Dec 2020 11:05:33 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: heikki.krogerus@linux.intel.com, linux@roeck-us.net Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Badhri Jagan Sridharan , Kyle Tso , Will McVicker , Greg Kroah-Hartman Subject: [PATCH 1/5] USB: typec: tcpm: Prevent log overflow by removing old entries Date: Thu, 10 Dec 2020 17:05:17 +0100 Message-Id: <20201210160521.3417426-2-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201210160521.3417426-1-gregkh@linuxfoundation.org> References: <20201210160521.3417426-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Badhri Jagan Sridharan TCPM logs overflow once the logbuffer is full. Clear old entries and allow logging the newer ones as the newer would be more relevant to the issue being debugged. Also, do not reset the logbuffer tail as end users might take back to back bugreports which would result in an empty buffer. Cc: Guenter Roeck Cc: Heikki Krogerus Cc: Kyle Tso Signed-off-by: Badhri Jagan Sridharan Signed-off-by: Will McVicker Signed-off-by: Greg Kroah-Hartman --- drivers/usb/typec/tcpm/tcpm.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index cedc6cf82d61..0ceeab50ed64 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -470,12 +470,6 @@ static bool tcpm_port_is_disconnected(struct tcpm_port *port) #ifdef CONFIG_DEBUG_FS -static bool tcpm_log_full(struct tcpm_port *port) -{ - return port->logbuffer_tail == - (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES; -} - __printf(2, 0) static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args) { @@ -495,11 +489,6 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args) vsnprintf(tmpbuffer, sizeof(tmpbuffer), fmt, args); - if (tcpm_log_full(port)) { - port->logbuffer_head = max(port->logbuffer_head - 1, 0); - strcpy(tmpbuffer, "overflow"); - } - if (port->logbuffer_head < 0 || port->logbuffer_head >= LOG_BUFFER_ENTRIES) { dev_warn(port->dev, @@ -519,6 +508,9 @@ static void _tcpm_log(struct tcpm_port *port, const char *fmt, va_list args) (unsigned long)ts_nsec, rem_nsec / 1000, tmpbuffer); port->logbuffer_head = (port->logbuffer_head + 1) % LOG_BUFFER_ENTRIES; + if (port->logbuffer_head == port->logbuffer_tail) + port->logbuffer_tail = + (port->logbuffer_tail + 1) % LOG_BUFFER_ENTRIES; abort: mutex_unlock(&port->logbuffer_lock); @@ -622,8 +614,6 @@ static int tcpm_debug_show(struct seq_file *s, void *v) seq_printf(s, "%s\n", port->logbuffer[tail]); tail = (tail + 1) % LOG_BUFFER_ENTRIES; } - if (!seq_has_overflowed(s)) - port->logbuffer_tail = tail; mutex_unlock(&port->logbuffer_lock); return 0; -- 2.29.2