This is a note to let you know that I've just added the patch titled mtd: spi-nor: core: Fix erase type discovery for overlaid region to the 5.4-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: mtd-spi-nor-core-fix-erase-type-discovery-for-overlaid-region.patch and it can be found in the queue-5.4 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 969b276718de37dfe66fce3a5633f611e8cd58fd Mon Sep 17 00:00:00 2001 From: Takahiro Kuwano <Takahiro.Kuwano@xxxxxxxxxxxx> Date: Fri, 2 Oct 2020 14:18:01 +0900 Subject: mtd: spi-nor: core: Fix erase type discovery for overlaid region From: Takahiro Kuwano <Takahiro.Kuwano@xxxxxxxxxxxx> commit 969b276718de37dfe66fce3a5633f611e8cd58fd upstream. In case of overlaid regions in which their biggest erase size command overpasses in size the region's size, only the non-overlaid portion of the sector gets erased. For example, if a Sector Erase command is applied to a 256-kB range that is overlaid by 4-kB sectors, the overlaid 4-kB sectors are not affected by the erase. For overlaid regions, 'region->size' is assigned to 'cmd->size' later in spi_nor_init_erase_cmd(), so 'erase->size' can be greater than 'len'. Fixes: 5390a8df769e ("mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories") Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Takahiro Kuwano <Takahiro.Kuwano@xxxxxxxxxxxx> [ta: Update commit description, add Fixes tag and Cc to stable] Signed-off-by: Tudor Ambarus <tudor.ambarus@xxxxxxxxxxxxx> Link: https://lore.kernel.org/r/fa5d8b944a5cca488ac54ba37c95e775ac2deb34.1601612872.git.Takahiro.Kuwano@xxxxxxxxxxxx Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/mtd/spi-nor/spi-nor.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1011,14 +1011,15 @@ spi_nor_find_best_erase_type(const struc erase = &map->erase_type[i]; + /* Alignment is not mandatory for overlaid regions */ + if (region->offset & SNOR_OVERLAID_REGION && + region->size <= len) + return erase; + /* Don't erase more than what the user has asked for. */ if (erase->size > len) continue; - /* Alignment is not mandatory for overlaid regions */ - if (region->offset & SNOR_OVERLAID_REGION) - return erase; - spi_nor_div_by_erase_size(erase, addr, &rem); if (rem) continue; Patches currently in stable-queue which might be from Takahiro.Kuwano@xxxxxxxxxxxx are queue-5.4/mtd-spi-nor-core-add-erase-size-check-for-erase-command-initialization.patch queue-5.4/mtd-spi-nor-sfdp-fix-wrong-erase-type-bitmask-for-overlaid-region.patch queue-5.4/mtd-spi-nor-sfdp-fix-last-erase-region-marking.patch queue-5.4/mtd-spi-nor-core-fix-erase-type-discovery-for-overlaid-region.patch