From patchwork Fri Jan 30 06:10:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 5746711 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0E35EBF440 for ; Fri, 30 Jan 2015 06:13:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 053B220251 for ; Fri, 30 Jan 2015 06:13:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 112D52024C for ; Fri, 30 Jan 2015 06:13:10 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YH4ms-0007DS-E7; Fri, 30 Jan 2015 06:10:38 +0000 Received: from mail-la0-x22b.google.com ([2a00:1450:4010:c03::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YH4mp-00079u-FU for linux-arm-kernel@lists.infradead.org; Fri, 30 Jan 2015 06:10:36 +0000 Received: by mail-la0-f43.google.com with SMTP id q1so22019806lam.2 for ; Thu, 29 Jan 2015 22:10:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=0pahBunwLIXRhELMEd6qyfm6OzlHgO6mt3Xhyh66GQw=; b=UVwV+FuW8pn1w1R17FDruSay6NVMY4tj6vgd9luE9YhyOYMNzpaGWg8yHkwfkLBRdJ Y/1pTo80NJzhtr2AwtJVaPdGAYeibmFpww4vqzZLFqXdLGQ5PlQ3B+ZvCbNJ6wLjafn+ hB6S3umfGeuDK4YiYuAtrsJZcUpY1YumR2ekU1DKa5Bqqrn2najQ6BlpNvpDKHJP0lZ3 Xl1ibk96R06Z/0GzB2TCfQFfa5dgmdJNIg40ICJu24ejP/+oZO9kvPuVZD+li2Uxp00F UgTfUeQp1JxwE0QIXvIWUtY7RQ5DsM7c4sePYvYYxmbMggZa6R/AEhAwYLMb69gFUduj IBWQ== X-Received: by 10.112.243.12 with SMTP id wu12mr4803492lbc.91.1422598212891; Thu, 29 Jan 2015 22:10:12 -0800 (PST) Received: from localhost.localdomain (x1-6-30-46-9a-6d-3c-54.cpe.webspeed.dk. [2.108.161.190]) by mx.google.com with ESMTPSA id n8sm997193lbd.1.2015.01.29.22.10.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jan 2015 22:10:12 -0800 (PST) From: Ricardo Ribalda Delgado To: Mark Brown , Michal Simek , =?UTF-8?q?S=C3=B6ren=20Brinkmann?= , linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] spi/xilinx: Fix access invalid memory on xilinx_spi_tx Date: Fri, 30 Jan 2015 07:10:09 +0100 Message-Id: <1422598209-5999-1-git-send-email-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150129_221035_714628_BB845BC5 X-CRM114-Status: GOOD ( 10.51 ) X-Spam-Score: -0.8 (/) Cc: Ricardo Ribalda Delgado X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 1 and 2 bytes per word, the transfer of the 3 last bytes will access memory outside rx_ptr. Although this has not trigger any error on real hardware, we should better fix this. Fixes: 24ba5e593f391507 Remove rx_fn and tx_fn pointer Signed-off-by: Ricardo Ribalda Delgado --- drivers/spi/spi-xilinx.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-xilinx.c b/drivers/spi/spi-xilinx.c index 2ca55f6..a1b664d 100644 --- a/drivers/spi/spi-xilinx.c +++ b/drivers/spi/spi-xilinx.c @@ -97,11 +97,26 @@ struct xilinx_spi { static void xilinx_spi_tx(struct xilinx_spi *xspi) { + u32 data = 0; + if (!xspi->tx_ptr) { xspi->write_fn(0, xspi->regs + XSPI_TXD_OFFSET); return; } - xspi->write_fn(*(u32 *)(xspi->tx_ptr), xspi->regs + XSPI_TXD_OFFSET); + + switch (xspi->bytes_per_word) { + case 1: + data = *(u8 *)(xspi->rx_ptr); + break; + case 2: + data = *(u16 *)(xspi->rx_ptr); + break; + case 4: + data = *(u32 *)(xspi->rx_ptr); + break; + } + + xspi->write_fn(data, xspi->regs + XSPI_TXD_OFFSET); xspi->tx_ptr += xspi->bytes_per_word; }