From 97a0e165a621c8b2d3b2e3e623ee1629166e66ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Fri, 24 Apr 2015 14:28:57 +0000 Subject: [PATCH] nvram: fix regression in finding NVRAM beginning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The loop was giving up too early as it never expected NVRAM smaller than 0x10000. Signed-off-by: Rafał Miłecki SVN-Revision: 45578 --- package/utils/nvram/src/nvram.c | 7 ++++++- package/utils/nvram/src/nvram.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package/utils/nvram/src/nvram.c b/package/utils/nvram/src/nvram.c index 0e1c7268375..c4bcb1d4a6f 100644 --- a/package/utils/nvram/src/nvram.c +++ b/package/utils/nvram/src/nvram.c @@ -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 ) { diff --git a/package/utils/nvram/src/nvram.h b/package/utils/nvram/src/nvram.h index cd37650860a..215d816327c 100644 --- a/package/utils/nvram/src/nvram.h +++ b/package/utils/nvram/src/nvram.h @@ -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 -- 2.30.2