From patchwork Mon Feb 2 10:06:56 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: 5760381 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9B6E89F269 for ; Mon, 2 Feb 2015 10:10:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B0722201FB for ; Mon, 2 Feb 2015 10:10:47 +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 963B3201F5 for ; Mon, 2 Feb 2015 10:10:46 +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 1YIDuh-0004WF-Vf; Mon, 02 Feb 2015 10:07:27 +0000 Received: from mail-la0-x230.google.com ([2a00:1450:4010:c03::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YIDue-0004Ql-74 for linux-arm-kernel@lists.infradead.org; Mon, 02 Feb 2015 10:07:25 +0000 Received: by mail-la0-f48.google.com with SMTP id pv20so38881555lab.7 for ; Mon, 02 Feb 2015 02:07:01 -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=N9m9mFP1U2/cValTEkUmLZlXlbVKcskB8bzR02Dm6KI=; b=kU7xZKbLGWZtUBD6PLxxg1RsmJJ526VzUgAworAGgPHRB/TXe3C0SxrXma3ugNOL9N TFQJ2kzIq9KdEjNUhD3SJNueXlU4PuD8X5oHrNFskpPm5ub6FDMAn3NqNp6VrsRoD3aX q3bD2dR6LVwAD+oVn4S0BD2R+c2qH2S6l1jllUI+cNHO3uZsC1HT2ZxnFpRBr/P+1wCN P0JBd3YSzRI8PJrFpeFBrcpsedIdOJ40Qy0kl4J981UjlJvXK2eQxWpB4m6p9EtTEZs9 yxmJGvuJ7IcEgjyr/GoxAu+EN7BCW4KJfuxDpJuR5fWEB2QHyOTJuaaKyJ4UyXvyIHNF A6fQ== X-Received: by 10.112.224.133 with SMTP id rc5mr14448474lbc.31.1422871620990; Mon, 02 Feb 2015 02:07:00 -0800 (PST) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by mx.google.com with ESMTPSA id ba3sm4288553lbc.35.2015.02.02.02.06.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Feb 2015 02:07:00 -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 v2] spi/xilinx: Fix access invalid memory on xilinx_spi_tx Date: Mon, 2 Feb 2015 11:06:56 +0100 Message-Id: <1422871616-6686-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-20150202_020724_462078_832AD50B X-CRM114-Status: GOOD ( 10.80 ) 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 tx_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 --- v2: v1 was completely wrong, sorry about that :(. This v2 has been tested on x86 1 byte per word 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 d1901d5..133f53a 100644 --- a/drivers/spi/spi-xilinx.c +++ b/drivers/spi/spi-xilinx.c @@ -117,11 +117,26 @@ static unsigned int xspi_read32_be(void __iomem *addr) 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->tx_ptr); + break; + case 2: + data = *(u16 *)(xspi->tx_ptr); + break; + case 4: + data = *(u32 *)(xspi->tx_ptr); + break; + } + + xspi->write_fn(data, xspi->regs + XSPI_TXD_OFFSET); xspi->tx_ptr += xspi->bytes_per_word; }