diff options
-rw-r--r-- | drivers/mtd/spi-nor/core.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index e0021dd34bfe..bc57b1b5ec62 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -1682,13 +1682,19 @@ static int spi_nor_sr_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) * * pow = ceil(log2(size / len)) = log2(size) - floor(log2(len)) */ - pow = ilog2(mtd->size) - ilog2(lock_len); - val = mask - (pow << SR_BP_SHIFT); - if (val & ~mask) - return -EINVAL; - /* Don't "lock" with no region! */ - if (!(val & mask)) - return -EINVAL; + if (lock_len == mtd->size) { + val = mask; + } else { + pow = ilog2(mtd->size) - ilog2(lock_len); + val = mask - (pow << SR_BP_SHIFT); + + if (val & ~mask) + return -EINVAL; + + /* Don't "lock" with no region! */ + if (!(val & mask)) + return -EINVAL; + } status_new = (status_old & ~mask & ~tb_mask) | val; |