You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2020/01/09 12:38:38 UTC

[incubator-nuttx] 01/07: drivers: mtd: smart: Fix handling of duplicate sector in smartfs

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 58f55d707f959f05dd28757458712f44484ec97e
Author: Alin Jerpelea <al...@sony.com>
AuthorDate: Thu Jan 11 00:43:39 2018 +0900

    drivers: mtd: smart: Fix handling of duplicate sector in smartfs
    
    In smartfs scan, if duplicate logical sector is found on the device,
    then smartfs selects the winner sector by comparing sequence number,
    and the loser sector is soon released. Fix a bug this loser sector
    is registered into logical-to-physical sector mapping table.
---
 drivers/mtd/smart.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c
index b7a5954..8f59a53 100644
--- a/drivers/mtd/smart.c
+++ b/drivers/mtd/smart.c
@@ -1991,6 +1991,10 @@ static int smart_scan(FAR struct smart_struct_s *dev)
 
   /* Now scan the MTD device */
 
+  /* At first, set the loser sector as the invalid value */
+
+  loser = totalsectors;
+
   for (sector = 0; sector < totalsectors; sector++)
     {
       finfo("Scan sector %d\n", sector);
@@ -2312,6 +2316,13 @@ static int smart_scan(FAR struct smart_struct_s *dev)
             }
         }
 
+      /* Test if this sector is loser of duplicate logical sector */
+
+      if (sector == loser)
+        {
+          continue;
+        }
+
 #ifndef CONFIG_MTD_SMART_MINIMIZE_RAM
       /* Update the logical to physical sector map */