From patchwork Thu Oct 23 13:36:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 402496 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 4EE52140095 for ; Fri, 24 Oct 2014 00:37:00 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 076FEA75EC; Thu, 23 Oct 2014 15:36:59 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0s47b9450IkJ; Thu, 23 Oct 2014 15:36:58 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5D081A75D8; Thu, 23 Oct 2014 15:36:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A59FCA75D8 for ; Thu, 23 Oct 2014 15:36:54 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6OsJJAZsBVkJ for ; Thu, 23 Oct 2014 15:36:54 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by theia.denx.de (Postfix) with ESMTPS id 3AB40A75D2 for ; Thu, 23 Oct 2014 15:36:50 +0200 (CEST) Received: by mail-pa0-f46.google.com with SMTP id fa1so1074268pad.33 for ; Thu, 23 Oct 2014 06:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=C0b0NiZeWgKEHnztYHnBTERFGNPewqfQ40hyuWJUbRA=; b=PULwlXIk8RfGKEQdj0l3tMoKH/bO2fFTgI3LUT2MjPTehBL1esM1OuJ4kQWAvmxwQ2 H2k6KmS8pOQdSoUMifr9qg4LdtaV3NB0HJ8FMj21qf6Slrf8mbhLoZakuTDDHWZMypsr 4gy1i8x3i0Pnt1rNRLt/bjRRnaZvo4N9nv/C5PHOpuyFrGUlQ34icLxvcRhTa/bcGl77 q/moFgN90CuNv79QwbiNh4m5p5evqV03PzTRF58yXm6Cxy2tdu2/9JT2X0sUAmKVhfZA C5XV7a6kGTe32PYEkZDf2s3P8twpNLO0Ps5ArRHgioAx+bkqOZdo+YAEMPGx41lhbs6c H+zA== X-Received: by 10.69.21.33 with SMTP id hh1mr5164704pbd.42.1414071398514; Thu, 23 Oct 2014 06:36:38 -0700 (PDT) Received: from localhost ([106.120.101.38]) by mx.google.com with ESMTPSA id d17sm1606424pdj.32.2014.10.23.06.36.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 23 Oct 2014 06:36:38 -0700 (PDT) From: Bin Meng To: Jagannadha Sutradharudu Teki , U-Boot Mailing List Date: Thu, 23 Oct 2014 21:36:31 +0800 Message-Id: <1414071391-16213-1-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 1.8.2.1 Subject: [U-Boot] [PATCH 1/5] spi/ich.c: Fix a bug of reading from a non-64 bytes aligned address X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de The ich spi controller driver spi_xfer() tries to align reading address to 64 bytes when doing spi data in, which causes a bug of either infinite loop or a huge size memcpy(). Actually the ich spi controller does not have such requirement of 64 bytes alignment when reading data from spi slave devices. Signed-off-by: Bin Meng Acked-by: Simon Glass Tested-by: Simon Glass --- drivers/spi/ich.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/drivers/spi/ich.c b/drivers/spi/ich.c index f5c6f3e..c4d3a29 100644 --- a/drivers/spi/ich.c +++ b/drivers/spi/ich.c @@ -483,8 +483,6 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, struct spi_trans *trans = &ich->trans; unsigned type = flags & (SPI_XFER_BEGIN | SPI_XFER_END); int using_cmd = 0; - /* Align read transactions to 64-byte boundaries */ - char buff[ctlr.databytes]; /* Ee don't support writing partial bytes. */ if (bitlen % 8) { @@ -632,14 +630,9 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, */ while (trans->bytesout || trans->bytesin) { uint32_t data_length; - uint32_t aligned_offset; - uint32_t diff; - - aligned_offset = trans->offset & ~(ctlr.databytes - 1); - diff = trans->offset - aligned_offset; /* SPI addresses are 24 bit only */ - ich_writel(aligned_offset & 0x00FFFFFF, ctlr.addr); + ich_writel(trans->offset & 0x00FFFFFF, ctlr.addr); if (trans->bytesout) data_length = min(trans->bytesout, ctlr.databytes); @@ -673,13 +666,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, } if (trans->bytesin) { - if (diff) { - data_length -= diff; - read_reg(ctlr.data, buff, ctlr.databytes); - memcpy(trans->in, buff + diff, data_length); - } else { - read_reg(ctlr.data, trans->in, data_length); - } + read_reg(ctlr.data, trans->in, data_length); spi_use_in(trans, data_length); if (with_address) trans->offset += data_length;