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:40 UTC

[incubator-nuttx] 03/07: drivers: mtd: smart: Fix error handling in smartfs mtd driver

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 82508e4e2fb54459e0d327bec5c959e392bcca09
Author: Alin Jerpelea <al...@sony.com>
AuthorDate: Tue Jan 30 16:52:07 2018 +0900

    drivers: mtd: smart: Fix error handling in smartfs mtd driver
    
    Add error handling in relocate sector.
---
 drivers/mtd/smart.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/smart.c b/drivers/mtd/smart.c
index eb5fa1e..406c793 100644
--- a/drivers/mtd/smart.c
+++ b/drivers/mtd/smart.c
@@ -3220,6 +3220,11 @@ static int smart_relocate_sector(FAR struct smart_struct_s *dev,
 
   ret = MTD_BWRITE(dev->mtd, newsector * dev->mtdblkspersector,
                    dev->mtdblkspersector, (FAR uint8_t *) dev->rwbuffer);
+  if (ret != dev->mtdblkspersector)
+    {
+      ferr("Error writing to new sector %d\n", newsector);
+      goto errout;
+    }
 
 #else   /* CONFIG_MTD_SMART_ENABLE_CRC */
 
@@ -3233,6 +3238,11 @@ static int smart_relocate_sector(FAR struct smart_struct_s *dev,
 
   ret = MTD_BWRITE(dev->mtd, newsector * dev->mtdblkspersector,
                    dev->mtdblkspersector, (FAR uint8_t *) dev->rwbuffer);
+  if (ret != dev->mtdblkspersector)
+    {
+      ferr("Error writing to new sector %d\n", newsector);
+      goto errout;
+    }
 
   /* Commit the sector */
 
@@ -3266,10 +3276,7 @@ static int smart_relocate_sector(FAR struct smart_struct_s *dev,
       ferr("ERROR: Error %d releasing old sector %d\n" -ret, oldsector);
     }
 
-#ifndef CONFIG_MTD_SMART_ENABLE_CRC
 errout:
-#endif
-
   return ret;
 }