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: 5760361 Return-Path: X-Original-To: patchwork-linux-spi@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 4A88EBF440 for ; Mon, 2 Feb 2015 10:07:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 834B620272 for ; Mon, 2 Feb 2015 10:07:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9FA4F2026F for ; Mon, 2 Feb 2015 10:07:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754759AbbBBKHF (ORCPT ); Mon, 2 Feb 2015 05:07:05 -0500 Received: from mail-la0-f43.google.com ([209.85.215.43]:43736 "EHLO mail-la0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933079AbbBBKHC (ORCPT ); Mon, 2 Feb 2015 05:07:02 -0500 Received: by mail-la0-f43.google.com with SMTP id q1so39044833lam.2; 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 Cc: Ricardo Ribalda Delgado 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 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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; }