nvram: fix regression in finding NVRAM beginning
authorRafał Miłecki <zajec5@gmail.com>
Fri, 24 Apr 2015 14:28:57 +0000 (14:28 +0000)
committerRafał Miłecki <zajec5@gmail.com>
Fri, 24 Apr 2015 14:28:57 +0000 (14:28 +0000)
The loop was giving up too early as it never expected NVRAM smaller
than 0x10000.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
SVN-Revision: 45578

package/utils/nvram/src/nvram.c
package/utils/nvram/src/nvram.h

index 0e1c7268375cc7b1d579820118326b63d3e8d272..c4bcb1d4a6f00a97f3fc7bfa2a0795f9cf4a7bb1 100644 (file)
@@ -364,7 +364,12 @@ nvram_handle_t * nvram_open(const char *file, int rdonly)
 
                if( mmap_area != MAP_FAILED )
                {
-                       for( i = 0; i <= ((nvram_part_size - NVRAM_SPACE) / sizeof(uint32_t)); i++ )
+                       /*
+                        * Start looking for NVRAM_MAGIC at beginning of MTD
+                        * partition. Stop if there is less than NVRAM_MIN_SPACE
+                        * to check, that was the lowest used size.
+                        */
+                       for( i = 0; i <= ((nvram_part_size - NVRAM_MIN_SPACE) / sizeof(uint32_t)); i++ )
                        {
                                if( ((uint32_t *)mmap_area)[i] == NVRAM_MAGIC )
                                {
index cd37650860a786e4c2007688272eb49f9486999a..215d816327c7e35adaff83f75bd253bf8d47fec8 100644 (file)
@@ -113,6 +113,7 @@ char * nvram_find_staging(void);
 #define        NVRAM_ROUNDUP(x, y)     ((((x)+((y)-1))/(y))*(y))
 
 /* NVRAM constants */
+#define NVRAM_MIN_SPACE                        0x8000
 #define NVRAM_SPACE                    0x10000
 #define NVRAM_MAGIC                    0x48534C46      /* 'FLSH' */
 #define NVRAM_VERSION          1