Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firmware: bcm47xx_nvram: inline code checking NVRAM size

Separated function was not improving code quality much (or at all).
Moreover it expected possible flash end address as argument and it was
returning NVRAM size.

The new code always operates on offsets which means less logic and less
calculations.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>

authored by

Rafał Miłecki and committed by
Thomas Bogendoerfer
f52da4cc 98b68324

+7 -18
+7 -18
drivers/firmware/broadcom/bcm47xx_nvram.c
··· 42 42 return ((struct nvram_header *)nvram)->magic == NVRAM_MAGIC; 43 43 } 44 44 45 - static u32 find_nvram_size(void __iomem *end) 46 - { 47 - int i; 48 - 49 - for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) { 50 - if (bcm47xx_nvram_is_valid(end - nvram_sizes[i])) 51 - return nvram_sizes[i]; 52 - } 53 - 54 - return 0; 55 - } 56 - 57 45 /** 58 46 * bcm47xx_nvram_copy - copy NVRAM to internal buffer 59 47 */ ··· 73 85 { 74 86 size_t flash_size; 75 87 size_t offset; 76 - u32 size; 88 + int i; 77 89 78 90 if (nvram_len) { 79 91 pr_warn("nvram already initialized\n"); ··· 81 93 } 82 94 83 95 /* TODO: when nvram is on nand flash check for bad blocks first. */ 96 + 97 + /* Try every possible flash size and check for NVRAM at its end */ 84 98 for (flash_size = FLASH_MIN; flash_size <= res_size; flash_size <<= 1) { 85 - /* Windowed flash access */ 86 - size = find_nvram_size(flash_start + flash_size); 87 - if (size) { 88 - offset = flash_size - size; 89 - goto found; 99 + for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) { 100 + offset = flash_size - nvram_sizes[i]; 101 + if (bcm47xx_nvram_is_valid(flash_start + offset)) 102 + goto found; 90 103 } 91 104 } 92 105