mtd: spi-nor: silently drop lock/unlock for already locked/unlocked region
Linux-MTD Mailing List
linux-mtd at lists.infradead.org
Thu Mar 24 11:59:11 PDT 2016
Gitweb: http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=4c0dba447ef4a97dfbae6e876312e952667eddc4
Commit: 4c0dba447ef4a97dfbae6e876312e952667eddc4
Parent: edf891ef9ab773363f8e58022a26d7d31604aed6
Author: Brian Norris <computersforpeace at gmail.com>
AuthorDate: Fri Jan 29 11:25:31 2016 -0800
Committer: Brian Norris <computersforpeace at gmail.com>
CommitDate: Mon Mar 7 18:01:54 2016 -0800
mtd: spi-nor: silently drop lock/unlock for already locked/unlocked region
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 <computersforpeace at gmail.com>
Reviewed-by: Ezequiel Garcia <ezequiel at vanguardiasur.com.ar>
Tested-by: Ezequiel Garcia <ezequiel at vanguardiasur.com.ar>
---
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 a9b3bdf2..3dde727 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);
More information about the linux-mtd-cvs
mailing list