From patchwork Fri Nov 20 18:26:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabio Estevam X-Patchwork-Id: 547020 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 DA9EE1402C2 for ; Sat, 21 Nov 2015 05:29:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=Z08QCvrr; 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 1ZzqOu-0006Oe-RQ; Fri, 20 Nov 2015 18:27:12 +0000 Received: from mail-yk0-x22e.google.com ([2607:f8b0:4002:c07::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZzqOr-0006F6-Us for linux-mtd@lists.infradead.org; Fri, 20 Nov 2015 18:27:10 +0000 Received: by ykdv3 with SMTP id v3so174290787ykd.0 for ; Fri, 20 Nov 2015 10:26:48 -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=9Ue6qp8/ndG08VpZX9GGVHkxG7gsGiTRMdGx0yCwXjg=; b=Z08QCvrr97/OJ0twPHHRViA+cGn+Ckjs3OyTit9rA/O/fN/npSbVRLJB9GtH5pFtRw dpkSyYIYXg4Yx6rJcI/NTVTSzFf68ZgsMQ2HZZ9mRUfHbNRfJYlptJmgMXZrdzGFTErE Y43VFwI3yy/JeDtiG7ixWkaxSovrRfSCy2CCEim00SCFAG7Si0rN5o/75oz12/VuNIad +m833mtpzzKUjn/ci0xlyhyZKwqZv8rbgqzWP9HsJuM2dyFDY5iEmtlrNOx0dK0R7w9Q 5fFSLXsvf5pnGfmvpioFokYllFt4KsiqkhqmBMbK+TZCJZzRGx9LHUag1pV+I/48voJ1 4+Lw== X-Received: by 10.129.102.69 with SMTP id a66mr4380003ywc.7.1448044008565; Fri, 20 Nov 2015 10:26:48 -0800 (PST) Received: from localhost.localdomain ([177.183.95.191]) by smtp.gmail.com with ESMTPSA id r63sm668607ywr.37.2015.11.20.10.26.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 Nov 2015 10:26:48 -0800 (PST) From: Fabio Estevam To: computersforpeace@gmail.com Subject: [PATCH v2] mtd: spi-nor: Check the return value from read_sr() Date: Fri, 20 Nov 2015 16:26:11 -0200 Message-Id: <1448043971-20230-1-git-send-email-festevam@gmail.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151120_102710_071595_3D89CBBA X-CRM114-Status: GOOD ( 11.11 ) 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:4002:c07:0:0:0:22e 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 (festevam[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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: Fabio Estevam , linux-mtd@lists.infradead.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Fabio Estevam We should better check the return value from read_sr() and propagate it in the case of error. Signed-off-by: Fabio Estevam --- Changes since v1: - Change status_old and status_new to int (Brian). drivers/mtd/spi-nor/spi-nor.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 16c9f55..b5e505d 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -459,11 +459,13 @@ static int stm_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len, static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) { struct mtd_info *mtd = &nor->mtd; - u8 status_old, status_new; + int status_old, status_new; u8 mask = SR_BP2 | SR_BP1 | SR_BP0; u8 shift = ffs(mask) - 1, pow, val; status_old = read_sr(nor); + if (status_old < 0) + return status_old; /* SPI NOR always locks to the end */ if (ofs + len != mtd->size) { @@ -509,11 +511,13 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len) { struct mtd_info *mtd = &nor->mtd; - uint8_t status_old, status_new; + int status_old, status_new; u8 mask = SR_BP2 | SR_BP1 | SR_BP0; u8 shift = ffs(mask) - 1, pow, val; status_old = read_sr(nor); + if (status_old < 0) + return status_old; /* Cannot unlock; would unlock larger region than requested */ if (stm_is_locked_sr(nor, status_old, ofs - mtd->erasesize, @@ -1013,6 +1017,8 @@ static int macronix_quad_enable(struct spi_nor *nor) int ret, val; val = read_sr(nor); + if (val < 0) + return val; write_enable(nor); write_sr(nor, val | SR_QUAD_EN_MX);