linux/drivers/mtd/spi-nor
Brian Norris f8860802da mtd: spi-nor: make lock/unlock bounds checks more obvious and robust
There are a few different corner cases to the current logic that seem
undesirable:

* mtd_lock() with offs==0 trips a bounds issue on
  ofs - mtd->erasesize < 0

* mtd_unlock() on the middle of a flash that is already unlocked will
  return -EINVAL

* probably other corner cases

So, let's stop doing "smart" checks like "check the block below us",
let's just do the following:

(a) pass only non-negative offsets/lengths to stm_is_locked_sr()
(b) add a similar stm_is_unlocked_sr() function, so we can check if the
    *entire* range is unlocked (and not just whether some part of it is
    unlocked)

Then armed with (b), we can make lock() and unlock() much more
symmetric:

(c) short-circuit the procedure if there is no work to be done, and
(d) check the entire range above/below

This also aligns well with the structure needed for proper TB
(Top/Bottom) support.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Tested-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
2016-03-07 18:01:54 -08:00
..
fsl-quadspi.c mtd: spi-nor: fsl-quadspi: add support for ls1021a 2016-03-07 11:46:44 -08:00
Kconfig mtd: spi-nor: fsl-quadspi: add support for layerscape 2016-03-07 11:46:44 -08:00
Makefile mtd: mtk-nor: new Mediatek serial flash controller driver 2015-11-20 17:35:16 -08:00
mtk-quadspi.c mtd: mtk-nor: Drop bogus __init from mtk_nor_init() 2016-01-15 09:47:00 -08:00
nxp-spifi.c mtd: spi-nor: drop unnecessary partition parser data 2015-11-11 13:58:51 -08:00
spi-nor.c mtd: spi-nor: make lock/unlock bounds checks more obvious and robust 2016-03-07 18:01:54 -08:00