Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp267869ybi; Wed, 29 May 2019 21:01:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqzS2T2288Wrm1UNVIbkQUZfrxzrd62hlxHg/53Q0EPNY+vVynuAX0Y8A4uTMqN37mDOieje X-Received: by 2002:a17:90a:9f93:: with SMTP id o19mr1802058pjp.70.1559188919799; Wed, 29 May 2019 21:01:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559188919; cv=none; d=google.com; s=arc-20160816; b=XrS3Gi0ixp+uoZtknjvzoPHzkdEFvxAcl+bLM92BssvgCEygOavuwKijgoUDkY7gmT YAHBJVwa1oiDd3qBWUTZkIGSel6lg5R5BYqCOWwZ0Ruf8Wc4wLMiFsZskdO4VkP4TU37 DqzxV5e0uUDOak5qDKsTQw/PngDu9kIImM78pmas5MSIyvwFz76QAtGQ56O/iR5fYJRC fAADbqnMuIDyQSFpSlQykQqW68DGyvTHwFfOdlf/tcVgtcKU8+k8TOQAMICJ8uX3FfLq fvjmlzDOL5jn0ApaYadgBa0LzJ/j61bj/MFMNQS8cKXvZoKqvQQ01+mLRg/GRd/Cjisk xOUw== 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=lUvOvarhSmQOSd1IEOwjK5sQd5/QWGbW4bFmKSRKw+c=; b=0d+E8Dh81nJdlBfoawUfN/RfUbWHttcYEb6Gy0rmeVoo6wi6trUvvJd9GKCLBpeI9Z A4gp1ZIsdzT5R1RMCLPu7B8Bd0jciZmmEOwIwRafz7VixhgSLDw95Sg1xl+eu+kLETRO 1CLxKN0/YYwnzBcT7DxrlKI4owzM0Brsa5JJjSdmQ/+MCnq6yMErvda18KitygaaKCx0 qr/zG1VEmHm4wXhHbfWfCJFmis6hhLX0bG23ldDMdcU5ofSKQXs7zpLSO8P9kn7lb1vx fAHld7CRSFdtxwFSmk+8FACHbsxJ7EQnEi6GBU8XKmdYsF2psMgRcj0FtwU26dgMtbYD MFWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UVJk64uq; 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 89si2111102plc.166.2019.05.29.21.01.44; Wed, 29 May 2019 21:01:59 -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; dkim=pass header.i=@kernel.org header.s=default header.b=UVJk64uq; 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 S1731545AbfE3EAb (ORCPT + 99 others); Thu, 30 May 2019 00:00:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:50966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730593AbfE3DSW (ORCPT ); Wed, 29 May 2019 23:18:22 -0400 Received: from localhost (ip67-88-213-2.z213-88-67.customer.algx.net [67.88.213.2]) (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 C5A3E247AF; Thu, 30 May 2019 03:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559186301; bh=EZBzuhK/Xg9IZDP/FXOwCB5SEoTCStbb2YO/OA05ksU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UVJk64uqHDoErSIdN9dyWHMtQxwUenB63MBwaxF2ZhUkkIjbKZipYHdvX9n+LjAzM cSZZMs1R+etnbjwaDgQu1zbnY6uL019t8YjvhgiBG9sHTAac5QCX4CnDQvTn+iGZi4 VXMeodLKUPD/ON/Q4Bqribsx4tpX4MlIzCbbyOjk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiada Wang , Fabio Estevam , Stefan Agner , Shawn Guo , Trent Piepho , Mark Brown , Sasha Levin Subject: [PATCH 4.19 267/276] spi: imx: stop buffer overflow in RX FIFO flush Date: Wed, 29 May 2019 20:07:05 -0700 Message-Id: <20190530030541.898993692@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190530030523.133519668@linuxfoundation.org> References: <20190530030523.133519668@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 [ Upstream commit c842749ea1d32513f9e603c074d60d7aa07cb2ef ] Commit 71abd29057cb ("spi: imx: Add support for SPI Slave mode") added an RX FIFO flush before start of a transfer. In slave mode, the master may have sent more data than expected and this data will still be in the RX FIFO at the start of the next transfer, and so needs to be flushed. However, the code to do the flush was accidentally saving this data into the previous transfer's RX buffer, clobbering the contents of whatever followed that buffer. Change it to empty the FIFO and throw away the data. Every one of the RX functions for the different eCSPI versions and modes reads the RX FIFO data using the same readl() call, so just use that, rather than using the spi_imx->rx function pointer and making sure all the different rx functions have a working "throw away" mode. There is another issue, which affects master mode when switching from DMA to PIO. There can be extra data in the RX FIFO which triggers this flush code, causing memory corruption in the same manner. I don't know why this data is unexpectedly in the FIFO. It's likely there is a different bug or erratum responsible for that. But regardless of that, I think this is proper fix the for bug at hand here. Fixes: 71abd29057cb ("spi: imx: Add support for SPI Slave mode") Cc: Jiada Wang Cc: Fabio Estevam Cc: Stefan Agner Cc: Shawn Guo Signed-off-by: Trent Piepho Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-imx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index 08dd3a31a3e5f..5b6f3655c366a 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -1427,7 +1427,7 @@ static int spi_imx_transfer(struct spi_device *spi, /* flush rxfifo before transfer */ while (spi_imx->devtype_data->rx_available(spi_imx)) - spi_imx->rx(spi_imx); + readl(spi_imx->base + MXC_CSPIRXDATA); if (spi_imx->slave_mode) return spi_imx_pio_transfer_slave(spi, transfer); -- 2.20.1