Received: by 10.192.165.156 with SMTP id m28csp1174470imm; Wed, 11 Apr 2018 13:55:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Id/C3YJJnGauCKiFvn8NGzLFyyBbwIJEctq3yPiZfXmxaAiUH5vROVm1rb57DEZku7iL4 X-Received: by 10.99.170.9 with SMTP id e9mr4506219pgf.331.1523480113186; Wed, 11 Apr 2018 13:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523480113; cv=none; d=google.com; s=arc-20160816; b=BhIcWDj7fFS9uglsfnIY79zN+dTrv3LZNquTExVkGZK8rXAVTV8v3X3qgnCNl/QI1Q 94+j3jYgF5XSFlFFJveWIepL3CCE8GdNHkvj28mrSYcwxzbLpmUQM2pUX4NFZyIXrlsk l5Zw2avOeZee4S1m2e2HqrlW4usM6KwEOWiV7nZk9m6iGr3+TlJKYBc+brCQ+qYLf23v aktJgqxFdABEo9/32Toau5LOYSJM3buVO+cDRvTn/RHqfAySybEjNAEsvubdUbi9UXQz /l2W1iNXUy2wj5SN+9N4RgWbhSYKzD/thhJQIG/nUHJ7SDHDyvDJ1P1/yFRM45xEuDdL b9Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=lUCrNVHr6ZVG139dEfVeuzniAZMhiFDX5ZU5MXEVIvM=; b=a5HiBadrVkOYj5SsH2wLTBjRGatIyhveBOf6CknXyVSUsIJr53Et9SqI+8vf9gFiuL HhpmSN3C3yLrvq1NusEv3cA+QTclKfvGA2ZkThTm2JwEoTLqr8GA8VIVv4cyKEKssJ4O pQDxf2EdciBj6Uo0zCeBtXkmJFBXZuqd0FOR5y8Inqpzo0Ug6RuOvVeCnp08S2ofpIqG fxENbJPxilPNOMUwn0I+Jih9tZ5n4ZudmSK7S2j0TwuMSc9khib7hNpExgNnTkEZZrY2 +wdoVHe1F39L7YUxb5Wc+wWkff+c1jAsILkcHjaRDJHCkSDJfkOo2GBuxTrFbagYU2Kc rAow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t190si1208076pgd.101.2018.04.11.13.54.36; Wed, 11 Apr 2018 13:55:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755547AbeDKSpe (ORCPT + 99 others); Wed, 11 Apr 2018 14:45:34 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58608 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755500AbeDKSpb (ORCPT ); Wed, 11 Apr 2018 14:45:31 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1F8BE2D; Wed, 11 Apr 2018 18:45:30 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Geert Uytterhoeven , Sasha Levin Subject: [PATCH 4.4 048/190] serial: sh-sci: Fix race condition causing garbage during shutdown Date: Wed, 11 Apr 2018 20:34:54 +0200 Message-Id: <20180411183553.074508354@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183550.114495991@linuxfoundation.org> References: <20180411183550.114495991@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Geert Uytterhoeven [ Upstream commit 1cf4a7efdc71cab84c42cfea7200608711ea954f ] If DMA is enabled and used, a burst of old data may be seen on the serial console during "poweroff" or "reboot". uart_flush_buffer() clears the circular buffer, but sci_port.tx_dma_len is not reset. This leads to a circular buffer overflow, dumping (UART_XMIT_SIZE - sci_port.tx_dma_len) bytes. To fix this, add a .flush_buffer() callback that resets sci_port.tx_dma_len. Inspired by commit 31ca2c63fdc0aee7 ("tty/serial: atmel: fix race condition (TX+DMA)"). Signed-off-by: Geert Uytterhoeven Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/sh-sci.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -1457,7 +1457,16 @@ static void sci_free_dma(struct uart_por if (s->chan_rx) sci_rx_dma_release(s, false); } -#else + +static void sci_flush_buffer(struct uart_port *port) +{ + /* + * In uart_flush_buffer(), the xmit circular buffer has just been + * cleared, so we have to reset tx_dma_len accordingly. + */ + to_sci_port(port)->tx_dma_len = 0; +} +#else /* !CONFIG_SERIAL_SH_SCI_DMA */ static inline void sci_request_dma(struct uart_port *port) { } @@ -1465,7 +1474,9 @@ static inline void sci_request_dma(struc static inline void sci_free_dma(struct uart_port *port) { } -#endif + +#define sci_flush_buffer NULL +#endif /* !CONFIG_SERIAL_SH_SCI_DMA */ static irqreturn_t sci_rx_interrupt(int irq, void *ptr) { @@ -2205,6 +2216,7 @@ static struct uart_ops sci_uart_ops = { .break_ctl = sci_break_ctl, .startup = sci_startup, .shutdown = sci_shutdown, + .flush_buffer = sci_flush_buffer, .set_termios = sci_set_termios, .pm = sci_pm, .type = sci_type,