You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/10/02 00:49:53 UTC

[GitHub] utzig closed pull request #1423: Fix double read on enc_flash driver

utzig closed pull request #1423: Fix double read on enc_flash driver
URL: https://github.com/apache/mynewt-core/pull/1423
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/hw/drivers/flash/enc_flash/src/enc_flash.c b/hw/drivers/flash/enc_flash/src/enc_flash.c
index 7f170bfc46..d2ac9af64d 100644
--- a/hw/drivers/flash/enc_flash/src/enc_flash.c
+++ b/hw/drivers/flash/enc_flash/src/enc_flash.c
@@ -159,7 +159,6 @@ enc_flash_is_empty(const struct hal_flash *h_dev, uint32_t addr, void *buf,
     struct enc_flash_dev *dev = HAL_TO_ENC(h_dev);
     const struct hal_flash *hwdev;
     int rc;
-    int rc2;
 
     hwdev = dev->efd_hwdev;
 
@@ -167,18 +166,18 @@ enc_flash_is_empty(const struct hal_flash *h_dev, uint32_t addr, void *buf,
         return hwdev->hf_itf->hff_is_empty(hwdev, addr, buf, len);
     } else {
         rc = hal_flash_is_erased(hwdev, addr, buf, len);
-        if (rc < 0) {
+
+        /*
+         * If error or low-level flash is erased, avoid reading it.
+         */
+        if (rc < 0 || rc == 1) {
             return rc;
         }
 
         /*
          * Also read the underlying data.
          */
-        rc2 = enc_flash_read(h_dev, addr, buf, len);
-        if (rc2 < 0) {
-            return rc2;
-        }
-        return rc;
+        return enc_flash_read(h_dev, addr, buf, len);
     }
 }
 
diff --git a/sys/flash_map/src/flash_map.c b/sys/flash_map/src/flash_map.c
index 98c3d35f80..1a10c546a8 100644
--- a/sys/flash_map/src/flash_map.c
+++ b/sys/flash_map/src/flash_map.c
@@ -189,25 +189,17 @@ flash_area_erased_val(const struct flash_area *fa)
 int
 flash_area_is_empty(const struct flash_area *fa, bool *empty)
 {
-    uint32_t data[64 >> 2];
-    uint32_t data_off = 0;
-    int8_t bytes_to_read;
     int rc;
 
-     while (data_off < fa->fa_size) {
-         bytes_to_read = min(64, fa->fa_size - data_off);
-         rc = hal_flash_isempty(fa->fa_device_id, fa->fa_off + data_off, data,
-                                bytes_to_read);
-         if (rc < 0) {
-             return rc;
-         } else if (rc == 0) {
-             *empty = false;
-             return 0;
-         }
-         data_off += bytes_to_read;
-     }
-     *empty = true;
-     return 0;
+    *empty = false;
+    rc = hal_flash_isempty_no_buf(fa->fa_device_id, fa->fa_off, fa->fa_size);
+    if (rc < 0) {
+        return rc;
+    } else if (rc == 1) {
+        *empty = true;
+    }
+
+    return 0;
 }
 
 int


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services