From patchwork Wed Dec 10 08:35:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 419448 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 310681400B7 for ; Wed, 10 Dec 2014 19:36:11 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 954DF4B72F; Wed, 10 Dec 2014 09:36:08 +0100 (CET) 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 U0IjiDBRejJY; Wed, 10 Dec 2014 09:36:08 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 13B764B736; Wed, 10 Dec 2014 09:36:08 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7E0CA4B736 for ; Wed, 10 Dec 2014 09:36:03 +0100 (CET) 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 IXkekqCbDTQW for ; Wed, 10 Dec 2014 09:36:03 +0100 (CET) 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-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by theia.denx.de (Postfix) with ESMTPS id 0A7FA4B72F for ; Wed, 10 Dec 2014 09:35:58 +0100 (CET) Received: by mail-pa0-f45.google.com with SMTP id lf10so1774532pab.32 for ; Wed, 10 Dec 2014 00:35:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=iutrsDA9YpRQjyk4Tro4mEWVKNPgvbZlY1saAao7GCk=; b=guPeec336zkOR2NOLUz4UGUeZnryikgA4/iGQz/qly7WJGLJ2myyTEDTlnT9SBmwmP pmsEv7/MwV9pZMUun7zqKvQhXlT7XN9xk9pgzp8uVgeKKBbGAMy0GjI+30tEChi2BvMT A7Y1+xhzpd3UU2ysZFsRfSV2o6No8GojbTm/wyWdG7yQJrDZJWLIWakvuo4gLKKLJT4a qirx/mdRxlvV8lhILDie/eEjYTyqysqAeSlowD39eNiiRyndzo7Z/0u0uCxqsZ9G6abp Mh4tZkrYZORIJk/KmvrKewUzvEIftAe8gBWA5XpVBSDh7ntMV5i+fOEgzLrZ7/9Lk0w3 /3Ww== X-Received: by 10.66.241.239 with SMTP id wl15mr4990621pac.15.1418200556788; Wed, 10 Dec 2014 00:35:56 -0800 (PST) Received: from localhost ([106.120.101.38]) by mx.google.com with ESMTPSA id z14sm3490940pdl.82.2014.12.10.00.35.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 10 Dec 2014 00:35:56 -0800 (PST) From: Bin Meng To: Simon Glass , Jagannadha Sutradharudu Teki , U-Boot Mailing List Date: Wed, 10 Dec 2014 16:35:50 +0800 Message-Id: <1418200550-4374-1-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 1.8.2.1 Subject: [U-Boot] [RESEND PATCH] x86: ich-spi: 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 --- RESEND Notes: Simon, this patch can be applied now as it does not require any dependency to Jagan's recent patch series, nor my x86 patch series. 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 0e00edf..7b24981 100644 --- a/drivers/spi/ich.c +++ b/drivers/spi/ich.c @@ -484,8 +484,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) { @@ -633,14 +631,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); @@ -674,13 +667,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;