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: 5746671 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 C366FBF440 for ; Fri, 30 Jan 2015 06:10:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE2002024D for ; Fri, 30 Jan 2015 06:10:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EEA482024C for ; Fri, 30 Jan 2015 06:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750923AbbA3GKQ (ORCPT ); Fri, 30 Jan 2015 01:10:16 -0500 Received: from mail-lb0-f173.google.com ([209.85.217.173]:63862 "EHLO mail-lb0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750887AbbA3GKP (ORCPT ); Fri, 30 Jan 2015 01:10:15 -0500 Received: by mail-lb0-f173.google.com with SMTP id p9so34833326lbv.4; Thu, 29 Jan 2015 22:10:13 -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 Cc: Ricardo Ribalda Delgado 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 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 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; }