From patchwork Fri Jan 29 19:25:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 575814 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 9F0AD140774 for ; Sat, 30 Jan 2016 06:28:28 +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=JBBhS7sE; 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 1aPEh7-00063m-GN; Fri, 29 Jan 2016 19:26:57 +0000 Received: from mail-pa0-x242.google.com ([2607:f8b0:400e:c03::242]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aPEgh-0005b7-9R for linux-mtd@lists.infradead.org; Fri, 29 Jan 2016 19:26:34 +0000 Received: by mail-pa0-x242.google.com with SMTP id yy13so3962635pab.1 for ; Fri, 29 Jan 2016 11:26:11 -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:in-reply-to:references; bh=1ikviGzgc+thXT3d2yUrxCGCeTaloA/JUL+DAddRYrs=; b=JBBhS7sE468kltUtDbQB+k3fcBZy5UeSHRwA7xacFPdLB9oFf9X+9DllmH5EL/tHc+ M7zkgAOXnszeGGmJ5SdMOY1ZqYKhnHICnAs0cdt3R3Qkxya+egwmc3SFiqFGC4kW4zLB aDY/U5E8DTGeZlNpUaamhrQ0HZDddcBaK8+x9SjHoY+tqX87tYzOnVIq+/v+N+yz7ZhL jeV6kVZaFi/559w9UUVZGcxs3od/at06M2mu0hebaHgqHcSbO5uC50TvfEWGHRHiii0Q 1GmomSMw1Pqsbgds8WziDZbDPVFJTEXYtWeSyIXrginHqUhsA+QNtpjIKqjCzo8mOPLv R8tw== 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=1ikviGzgc+thXT3d2yUrxCGCeTaloA/JUL+DAddRYrs=; b=RXQsirmRiNS8ba638lEcbrsOk38zmTh3eE1t67ncBc3p5fOXsNpf070wBZfZ467xVK zZDWllzbz+A08Fz44GQGJhEqBou4/ypduNn8qbHCHNOHuNgT0zyl6388KdVyhIOQ7mz1 Kx9dEkji3hpoR1VUY3wKCz1WoNNCNAcX8QlHtZbWdPahPKZBiGDY1A7BF17YOv6bn93V ij7McEDD6OvOoBxhNd542QJ39WbZRxa1Mi+8CYsBVZsI/cNgB4Dd/9CTbJJaa33ZI4Pv 09Wkc5YgmDUu2UdRO8NTCxG5a/2a/59/r8LoJkYTAX1wxsXVBmG9vNSlOI/MQ8EMIg39 cJLQ== X-Gm-Message-State: AG10YORfebeexEokRLuGX/S8VhSo6sGiWspUc+QIdTTNhz+2x+Qb7/ujupNWR7qlW6oGEw== X-Received: by 10.66.186.170 with SMTP id fl10mr16129725pac.134.1454095570836; Fri, 29 Jan 2016 11:26:10 -0800 (PST) Received: from ban.mtv.corp.google.com ([172.22.64.120]) by smtp.gmail.com with ESMTPSA id dg12sm25264001pac.47.2016.01.29.11.26.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Jan 2016 11:26:10 -0800 (PST) From: Brian Norris To: Subject: [PATCH v2 2/8] mtd: spi-nor: silently drop lock/unlock for already locked/unlocked region Date: Fri, 29 Jan 2016 11:25:31 -0800 Message-Id: <1454095537-130536-3-git-send-email-computersforpeace@gmail.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1454095537-130536-1-git-send-email-computersforpeace@gmail.com> References: <1454095537-130536-1-git-send-email-computersforpeace@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160129_112631_556272_AD7A3129 X-CRM114-Status: GOOD ( 11.13 ) 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:242 listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (computersforpeace[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -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_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 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: Marek Vasut , Boris Brezillon , djkurtz@chromium.org, =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , linux-kernel@vger.kernel.org, Bayi Cheng , Ezequiel Garcia , Brian Norris MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If, for instance, the entire flash is already unlocked and I try to mtd_unlock() the entire device, I don't expect to see an EINVAL error. It should just silently succeed. Ditto for mtd_lock(). Signed-off-by: Brian Norris Reviewed-by: Ezequiel Garcia --- v2: no change drivers/mtd/spi-nor/spi-nor.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index ef89bed1e5ea..77c88ac69ef9 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -515,8 +515,12 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) status_new = (status_old & ~mask) | val; + /* Don't bother if they're the same */ + if (status_new == status_old) + return 0; + /* Only modify protection if it will not unlock other areas */ - if ((status_new & mask) <= (status_old & mask)) + if ((status_new & mask) < (status_old & mask)) return -EINVAL; write_enable(nor); @@ -569,8 +573,12 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len) status_new = (status_old & ~mask) | val; + /* Don't bother if they're the same */ + if (status_new == status_old) + return 0; + /* Only modify protection if it will not lock other areas */ - if ((status_new & mask) >= (status_old & mask)) + if ((status_new & mask) > (status_old & mask)) return -EINVAL; write_enable(nor);