From patchwork Fri May 6 00:31:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 619098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r1CTg1ySQz9t6v for ; Fri, 6 May 2016 10:34:47 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=eycrLIek; dkim-atps=neutral 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 1ayThX-0006nK-4G; Fri, 06 May 2016 00:33:03 +0000 Received: from mail-pa0-x231.google.com ([2607:f8b0:400e:c03::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ayThQ-0006LR-SJ for linux-mtd@lists.infradead.org; Fri, 06 May 2016 00:32:57 +0000 Received: by mail-pa0-x231.google.com with SMTP id r5so42357925pag.1 for ; Thu, 05 May 2016 17:32:36 -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:in-reply-to:references; bh=kE9FZkPeReKiJKCsoeCyviFZaZE6bu3J+TKQnISdut4=; b=eycrLIek4dYASzGhAd/pR3JSz4B1GOD2BXPUuY1dvf3se6A9Eo6nnGymc/B0g57iO/ rQQIRwrbzD3Ol9OYpDXjNdETYRUXTHecxIGaes2LFmS60yVcUompgQA0Dz6s8yAzjIsd ZZVxYN06ByiNk/HwBTgQFPDXQ+sGidz+5JuE/N/p/i7eBiYqqp685O806y78AF3IB/3d HGLPS0wbNIw1KZHanlYNj3hnkfovmLEANo3YA8mLsKugZkJF930Nb0T47lXDv9a/yNKB FmyyqIWcMpPWFX1ngEbrlrETz/f2ZyUyChdcXq6HOGBz4bKVlTR0M+1TlavycKufEh+K fD1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kE9FZkPeReKiJKCsoeCyviFZaZE6bu3J+TKQnISdut4=; b=ci12Hpil0zPyYVP49Q2Hji1+r5/Z1wUGEZwckwUhw0a0jdGSFc0h2l/wHa9BVO3Im5 5Ip+gEcBgmffmPkw7LXYAIeVSpt/KFGmedpSm9J4Rto8DtkUtC3qg228+Gv3G0Jj9a32 JE59rPJBluBPDnLINu9Sl3aodbgberYFs/1lLnUMiBzTFioneLanv3XbC93rfyno/TMe WkpHX80PjXQh4ySee9VO5Fy2qmLITFacuwxYYfWA0UMGA0zBPcou82gnOzFjBFgL4Tmm axZ6VOoFQcdvHcyGVcztTY/OUWXaNPGNLZqDqN+Um/48x51ngTqkNzcMsFrn1+dDyhLw 5b7Q== X-Gm-Message-State: AOPr4FUt+rIsn1ntaZau2eSkYjFikQhMNAR6g6d0h59T0fblQ1g4v2rQkYeqkuIPBeAYeg== X-Received: by 10.66.25.243 with SMTP id f19mr24771368pag.11.1462494756205; Thu, 05 May 2016 17:32:36 -0700 (PDT) Received: from ban.mtv.corp.google.com ([172.22.64.120]) by smtp.gmail.com with ESMTPSA id n10sm16337821pax.18.2016.05.05.17.32.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 May 2016 17:32:35 -0700 (PDT) From: Brian Norris To: Subject: [PATCH v7 02/10] mtd: m25p80: return amount of data transferred or error in read/write Date: Thu, 5 May 2016 17:31:48 -0700 Message-Id: <1462494716-95312-3-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1462494716-95312-1-git-send-email-computersforpeace@gmail.com> References: <1462494716-95312-1-git-send-email-computersforpeace@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160505_173256_946139_9EB790F0 X-CRM114-Status: GOOD ( 13.00 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:400e:c03:0:0:0:231 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boris Brezillon , Michal Suchanek , Gabor Juhos , Bean Huo , Rafal Milecki , linux-kernel@vger.kernel.org, Bayi Cheng , "Andrew F. Davis" , Javier Martinez Canillas , Jagan Teki , Han Xu , Cyrille Pitchen , Brian Norris , Mika Westerberg , Joachim Eastwood , Heiner Kallweit MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Michal Suchanek Add checking of SPI transfer errors and return them from read/write functions. Also return the amount of data transferred. Signed-off-by: Michal Suchanek Signed-off-by: Brian Norris --- v6 -> v7: * handle the special spi_flash_read() SPI support that has been added recently drivers/mtd/devices/m25p80.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 3bd75e87ed89..2ef5a6015276 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -81,6 +81,7 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len, struct spi_transfer t[2] = {}; struct spi_message m; int cmd_sz = m25p_cmdsz(nor); + ssize_t ret; spi_message_init(&m); @@ -98,10 +99,15 @@ static ssize_t m25p80_write(struct spi_nor *nor, loff_t to, size_t len, t[1].len = len; spi_message_add_tail(&t[1], &m); - spi_sync(spi, &m); + ret = spi_sync(spi, &m); + if (ret) + return ret; - *retlen += m.actual_length - cmd_sz; - return 0; + ret = m.actual_length - cmd_sz; + if (ret < 0) + return -EIO; + *retlen += ret; + return ret; } static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor) @@ -128,13 +134,13 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, struct spi_transfer t[2]; struct spi_message m; unsigned int dummy = nor->read_dummy; + ssize_t ret; /* convert the dummy cycles to the number of bytes */ dummy /= 8; if (spi_flash_read_supported(spi)) { struct spi_flash_read_message msg; - int ret; memset(&msg, 0, sizeof(msg)); @@ -151,7 +157,9 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, ret = spi_flash_read(spi, &msg); *retlen = msg.retlen; - return ret; + if (ret < 0) + return ret; + return msg.retlen; } spi_message_init(&m); @@ -169,10 +177,15 @@ static ssize_t m25p80_read(struct spi_nor *nor, loff_t from, size_t len, t[1].len = len; spi_message_add_tail(&t[1], &m); - spi_sync(spi, &m); + ret = spi_sync(spi, &m); + if (ret) + return ret; - *retlen = m.actual_length - m25p_cmdsz(nor) - dummy; - return 0; + ret = m.actual_length - m25p_cmdsz(nor) - dummy; + if (ret < 0) + return -EIO; + *retlen += ret; + return ret; } /*