diff options
author | Roger Quadros <rogerq@ti.com> | 2015-02-23 10:26:39 -0500 |
---|---|---|
committer | Brian Norris <computersforpeace@gmail.com> | 2015-03-30 20:39:15 -0400 |
commit | 60c70d66cdd39eb560bba5a95c429bf2ad5294d0 (patch) | |
tree | 52eb33f58905f89256ebd8836ff25af072b65f16 /drivers/mtd | |
parent | 8cc7f33aadc8fb37b5a3f4c46f5fa83748a92a01 (diff) |
mtd: nand: Prevent possible kernel lockup in nand_command()
If a NAND device is not really present or pin muxes are not correctly
configured we can lock up the kernel waiting infinitely for NAND_STATUS
to be ready.
This can be easily reproduced on TI's DRA7-evm board by booting it
without NAND support in u-boot and disabling NAND pin muxes in the kernel.
Add timeout when waiting for NAND_CMD_RESET completion. As per ONFi v4.0
tRST can be upto 250ms for EZ-NAND and 5ms for raw NAND.
Signed-off-by: Roger Quadros <rogerq@ti.com>
Tested-by: Nishanth Menon <nm@ti.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/nand/nand_base.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index ff5652211607..c2e1232cd45c 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -566,6 +566,25 @@ void nand_wait_ready(struct mtd_info *mtd) | |||
566 | EXPORT_SYMBOL_GPL(nand_wait_ready); | 566 | EXPORT_SYMBOL_GPL(nand_wait_ready); |
567 | 567 | ||
568 | /** | 568 | /** |
569 | * nand_wait_status_ready - [GENERIC] Wait for the ready status after commands. | ||
570 | * @mtd: MTD device structure | ||
571 | * @timeo: Timeout in ms | ||
572 | * | ||
573 | * Wait for status ready (i.e. command done) or timeout. | ||
574 | */ | ||
575 | static void nand_wait_status_ready(struct mtd_info *mtd, unsigned long timeo) | ||
576 | { | ||
577 | register struct nand_chip *chip = mtd->priv; | ||
578 | |||
579 | timeo = jiffies + msecs_to_jiffies(timeo); | ||
580 | do { | ||
581 | if ((chip->read_byte(mtd) & NAND_STATUS_READY)) | ||
582 | break; | ||
583 | touch_softlockup_watchdog(); | ||
584 | } while (time_before(jiffies, timeo)); | ||
585 | }; | ||
586 | |||
587 | /** | ||
569 | * nand_command - [DEFAULT] Send command to NAND device | 588 | * nand_command - [DEFAULT] Send command to NAND device |
570 | * @mtd: MTD device structure | 589 | * @mtd: MTD device structure |
571 | * @command: the command to be sent | 590 | * @command: the command to be sent |
@@ -643,8 +662,8 @@ static void nand_command(struct mtd_info *mtd, unsigned int command, | |||
643 | NAND_CTRL_CLE | NAND_CTRL_CHANGE); | 662 | NAND_CTRL_CLE | NAND_CTRL_CHANGE); |
644 | chip->cmd_ctrl(mtd, | 663 | chip->cmd_ctrl(mtd, |
645 | NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); | 664 | NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); |
646 | while (!(chip->read_byte(mtd) & NAND_STATUS_READY)) | 665 | /* EZ-NAND can take upto 250ms as per ONFi v4.0 */ |
647 | ; | 666 | nand_wait_status_ready(mtd, 250); |
648 | return; | 667 | return; |
649 | 668 | ||
650 | /* This applies to read commands */ | 669 | /* This applies to read commands */ |
@@ -740,8 +759,8 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, | |||
740 | NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE); | 759 | NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE); |
741 | chip->cmd_ctrl(mtd, NAND_CMD_NONE, | 760 | chip->cmd_ctrl(mtd, NAND_CMD_NONE, |
742 | NAND_NCE | NAND_CTRL_CHANGE); | 761 | NAND_NCE | NAND_CTRL_CHANGE); |
743 | while (!(chip->read_byte(mtd) & NAND_STATUS_READY)) | 762 | /* EZ-NAND can take upto 250ms as per ONFi v4.0 */ |
744 | ; | 763 | nand_wait_status_ready(mtd, 250); |
745 | return; | 764 | return; |
746 | 765 | ||
747 | case NAND_CMD_RNDOUT: | 766 | case NAND_CMD_RNDOUT: |