Skip to content

Commit 1de1ad0

Browse files
Joakim Tjernlundgregkh
authored andcommitted
mtd: cfi: cmdset_0001: Do not allow read/write to suspend erase block.
commit 6510bbc upstream. Currently it is possible to read and/or write to suspend EB's. Writing /dev/mtdX or /dev/mtdblockX from several processes may break the flash state machine. Signed-off-by: Joakim Tjernlund <joakim.tjernlund@infinera.com> Cc: <stable@vger.kernel.org> Reviewed-by: Richard Weinberger <richard@nod.at> Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6c677c5 commit 1de1ad0

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎drivers/mtd/chips/cfi_cmdset_0001.c‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -831,21 +831,25 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
831831
(mode == FL_WRITING && (cfip->SuspendCmdSupport & 1))))
832832
goto sleep;
833833

834+
/* Do not allow suspend iff read/write to EB address */
835+
if ((adr & chip->in_progress_block_mask) ==
836+
chip->in_progress_block_addr)
837+
goto sleep;
834838

835839
/* Erase suspend */
836-
map_write(map, CMD(0xB0), adr);
840+
map_write(map, CMD(0xB0), chip->in_progress_block_addr);
837841

838842
/* If the flash has finished erasing, then 'erase suspend'
839843
* appears to make some (28F320) flash devices switch to
840844
* 'read' mode. Make sure that we switch to 'read status'
841845
* mode so we get the right data. --rmk
842846
*/
843-
map_write(map, CMD(0x70), adr);
847+
map_write(map, CMD(0x70), chip->in_progress_block_addr);
844848
chip->oldstate = FL_ERASING;
845849
chip->state = FL_ERASE_SUSPENDING;
846850
chip->erase_suspended = 1;
847851
for (;;) {
848-
status = map_read(map, adr);
852+
status = map_read(map, chip->in_progress_block_addr);
849853
if (map_word_andequal(map, status, status_OK, status_OK))
850854
break;
851855

@@ -1041,8 +1045,8 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
10411045
sending the 0x70 (Read Status) command to an erasing
10421046
chip and expecting it to be ignored, that's what we
10431047
do. */
1044-
map_write(map, CMD(0xd0), adr);
1045-
map_write(map, CMD(0x70), adr);
1048+
map_write(map, CMD(0xd0), chip->in_progress_block_addr);
1049+
map_write(map, CMD(0x70), chip->in_progress_block_addr);
10461050
chip->oldstate = FL_READY;
10471051
chip->state = FL_ERASING;
10481052
break;
@@ -1933,6 +1937,8 @@ static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip,
19331937
map_write(map, CMD(0xD0), adr);
19341938
chip->state = FL_ERASING;
19351939
chip->erase_suspended = 0;
1940+
chip->in_progress_block_addr = adr;
1941+
chip->in_progress_block_mask = ~(len - 1);
19361942

19371943
ret = INVAL_CACHE_AND_WAIT(map, chip, adr,
19381944
adr, len,

‎include/linux/mtd/flashchip.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct flchip {
8585
unsigned int write_suspended:1;
8686
unsigned int erase_suspended:1;
8787
unsigned long in_progress_block_addr;
88+
unsigned long in_progress_block_mask;
8889

8990
struct mutex mutex;
9091
wait_queue_head_t wq; /* Wait on here when we're waiting for the chip

0 commit comments

Comments
 (0)