This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch pr66 in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 60927c5fb6a353994341601f55071c618e97682b Author: Alin Jerpelea <[email protected]> AuthorDate: Thu Dec 28 18:27:21 2017 +0900 drivers: mtd: smart: Fix duplicate sector selection in SmartFS Add care for 16-bit sequence without CRC. --- drivers/mtd/smart.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c index e011195..f9c9b2a 100644 --- a/drivers/mtd/smart.c +++ b/drivers/mtd/smart.c @@ -1874,6 +1874,7 @@ static int smart_scan(FAR struct smart_struct_s *dev) uint32_t offset; uint16_t seq1; uint16_t seq2; + uint16_t seqwrap; struct smart_sect_header_s header; #ifdef CONFIG_MTD_SMART_MINIMIZE_RAM int dupsector; @@ -2179,7 +2180,8 @@ static int smart_scan(FAR struct smart_struct_s *dev) */ #if SMART_STATUS_VERSION == 1 - if (header.status & SMART_STATUS_CRC) + if ((header.status & SMART_STATUS_CRC) != + (CONFIG_SMARTFS_ERASEDSTATE & SMART_STATUS_CRC)) { seq2 = header.seq; } @@ -2266,21 +2268,25 @@ static int smart_scan(FAR struct smart_struct_s *dev) } #if SMART_STATUS_VERSION == 1 - if (header.status & SMART_STATUS_CRC) + if ((header.status & SMART_STATUS_CRC) != + (CONFIG_SMARTFS_ERASEDSTATE & SMART_STATUS_CRC)) { seq1 = header.seq; + seqwrap = 0xf0; } else { seq1 = *((FAR uint16_t *) &header.seq); + seqwrap = 0xfff0; } #else seq1 = header.seq; + seqwrap = 0xf0; #endif /* Now determine who wins */ - if ((seq1 > 0xfff0 && seq2 < 10) || seq2 > seq1) + if ((seq1 > seqwrap && seq2 < 10) || seq2 > seq1) { /* Seq 2 is the winner ... bigger or it wrapped */ @@ -3222,7 +3228,8 @@ static int smart_relocate_sector(FAR struct smart_struct_s *dev, /* Increment the sequence number and clear the "commit" flag */ #if SMART_STATUS_VERSION == 1 - if (header->status & SMART_STATUS_CRC) + if ((header->status & SMART_STATUS_CRC) != + (CONFIG_SMARTFS_ERASEDSTATE & SMART_STATUS_CRC)) { #endif /* Using 8-bit sequence */ @@ -4571,7 +4578,8 @@ static int smart_writesector(FAR struct smart_struct_s *dev, /* Update the sequence number to indicate the sector was moved */ #if SMART_STATUS_VERSION == 1 - if (header->status & SMART_STATUS_CRC) + if ((header->status & SMART_STATUS_CRC) != + (CONFIG_SMARTFS_ERASEDSTATE & SMART_STATUS_CRC)) { #endif header->seq++;
