Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp128585ybm; Tue, 26 May 2020 12:29:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCUPVff4VK6mq8OpE5TTpw3xUtMAnaruT5Ru4rNqtI0SCsJja7cO5jpd2Nh7BKJwmMRhHz X-Received: by 2002:a17:906:46d3:: with SMTP id k19mr2562601ejs.349.1590521343226; Tue, 26 May 2020 12:29:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590521343; cv=none; d=google.com; s=arc-20160816; b=iAnNgfEqGuu/qMr0RBhWRApONi7gZdce8pWTS/9eLeQu6GGJcdw4pKpFCZBd+OB9/H Xo6+T27BF0nB/+TiVusWWbpLP8ogORFQP2XPo4hq4iO676GauRJEqSG9GL4aKnKQBFvZ d47Lx7+uwzHJsotA+9hoEee1Dt+/vY57UYM68rajXJaarctf6KTS2V9t22PDZi6SXSL0 bhSeXfpe78m2k8c7vpBLyq0Yd/tcQYXyQVHsDBCOQmZcuZjYMjp1z73CiDNvEwEddMZA hSiuzJAG9DSHl3VKrf5HZohnZqZuv4OwN+S+bH9xnoVYEuhIsWv2m7iCBrXiOlQlBYzk 3VzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RsTZjhgDX4XGMfynlxopAtqnLXPr0FMFz8dTMzxrZQg=; b=K/dk+LY/n6N+p4OuxJeXnMOvkQjVw0t6lyc9jihC2JyShQxwLSW9wpiZCGlK91eSvB gejFyiKFKoA3zuNKxVYnbS9ehKjR8hREzn9fmHUwulX2M/awVJVtK9pQGSMBhdn6pmKL edv5Y+uzX/TaRakBnm94uAl+CEsT2c70uKCO0PVKaiQqsQqXZjwpD/rzHWrR5NqRQwdI Z1OcBETuBN8/dMKKGX/5mARCh/B89cCtTDhydBw2BRNd7NvZnVNcItbTAlpc/Z2AjFLk cWQPLpSoI2bna376sWjsA6lNW91SGwENQK3cLAWJyXA1ZVoL9gC+CV6VKk9HDlxa+AVQ EvKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=D1pkQgGh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f8si543911edk.160.2020.05.26.12.28.40; Tue, 26 May 2020 12:29:03 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=D1pkQgGh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391567AbgEZTGT (ORCPT + 99 others); Tue, 26 May 2020 15:06:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:34278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403867AbgEZTGK (ORCPT ); Tue, 26 May 2020 15:06:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 75E5A20776; Tue, 26 May 2020 19:06:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590519968; bh=H3zYurp4vws08k5KeeuCCQoUZXnK6XFe5PA6kHN1Gm0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D1pkQgGh3cyaKGm99TzyjpviPVa13cHx3170afuQMpyeOmciUVU57Rzp9da1WDNk2 ROm4wzUOPyJV7Dx3G1ry4unN5WPXKmS5nVxNoQ5y1xwgiBRpeuSK5dxI5ZAwhWFRES 6jVfJqNRuds42JvArtB9EYMx7LKwA9uBhAyMZ8tc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthias Kaehlcke , Evan Green , Ryan Case , Sasha Levin Subject: [PATCH 4.19 62/81] tty: serial: qcom_geni_serial: Fix wrap around of TX buffer Date: Tue, 26 May 2020 20:53:37 +0200 Message-Id: <20200526183933.937416893@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526183923.108515292@linuxfoundation.org> References: <20200526183923.108515292@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthias Kaehlcke [ Upstream commit 3c66eb4ba18dd1cab0d1bde651cde6d8bdb47696 ] Before commit a1fee899e5bed ("tty: serial: qcom_geni_serial: Fix softlock") the size of TX transfers was limited to the TX FIFO size, and wrap arounds of the UART circular buffer were split into two transfers. With the commit wrap around are allowed within a transfer. The TX FIFO of the geni serial port uses a word size of 4 bytes. In case of a circular buffer wrap within a transfer the driver currently may write an incomplete word to the FIFO, with some bytes containing data from the circular buffer and others being zero. Since the transfer isn't completed yet the zero bytes are sent as if they were actual data. Handle wrap arounds of the TX buffer properly and ensure that words written to the TX FIFO always contain valid data (unless the transfer is completed). Fixes: a1fee899e5bed ("tty: serial: qcom_geni_serial: Fix softlock") Signed-off-by: Matthias Kaehlcke Reviewed-by: Evan Green Tested-by: Ryan Case Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/qcom_geni_serial.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c index 4458419f053b..0d405cc58e72 100644 --- a/drivers/tty/serial/qcom_geni_serial.c +++ b/drivers/tty/serial/qcom_geni_serial.c @@ -705,7 +705,7 @@ static void qcom_geni_serial_handle_tx(struct uart_port *uport, bool done, avail *= port->tx_bytes_pw; tail = xmit->tail; - chunk = min3(avail, pending, (size_t)(UART_XMIT_SIZE - tail)); + chunk = min(avail, pending); if (!chunk) goto out_write_wakeup; @@ -727,19 +727,21 @@ static void qcom_geni_serial_handle_tx(struct uart_port *uport, bool done, memset(buf, 0, ARRAY_SIZE(buf)); tx_bytes = min_t(size_t, remaining, port->tx_bytes_pw); - for (c = 0; c < tx_bytes ; c++) - buf[c] = xmit->buf[tail + c]; + + for (c = 0; c < tx_bytes ; c++) { + buf[c] = xmit->buf[tail++]; + tail &= UART_XMIT_SIZE - 1; + } iowrite32_rep(uport->membase + SE_GENI_TX_FIFOn, buf, 1); i += tx_bytes; - tail += tx_bytes; uport->icount.tx += tx_bytes; remaining -= tx_bytes; port->tx_remaining -= tx_bytes; } - xmit->tail = tail & (UART_XMIT_SIZE - 1); + xmit->tail = tail; /* * The tx fifo watermark is level triggered and latched. Though we had -- 2.25.1