1 From f52da4ccfec9192e17f5c16260dfdd6d3ea76f65 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
3 Date: Mon, 8 Mar 2021 10:03:20 +0100
4 Subject: [PATCH] firmware: bcm47xx_nvram: inline code checking NVRAM size
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Separated function was not improving code quality much (or at all).
10 Moreover it expected possible flash end address as argument and it was
13 The new code always operates on offsets which means less logic and less
16 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
19 drivers/firmware/broadcom/bcm47xx_nvram.c | 25 +++++++----------------
20 1 file changed, 7 insertions(+), 18 deletions(-)
22 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c
23 +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c
24 @@ -42,18 +42,6 @@ static bool bcm47xx_nvram_is_valid(void
25 return ((struct nvram_header *)nvram)->magic == NVRAM_MAGIC;
28 -static u32 find_nvram_size(void __iomem *end)
32 - for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
33 - if (bcm47xx_nvram_is_valid(end - nvram_sizes[i]))
34 - return nvram_sizes[i];
41 * bcm47xx_nvram_copy - copy NVRAM to internal buffer
43 @@ -85,7 +73,7 @@ static int bcm47xx_nvram_find_and_copy(v
51 pr_warn("nvram already initialized\n");
52 @@ -93,12 +81,13 @@ static int bcm47xx_nvram_find_and_copy(v
55 /* TODO: when nvram is on nand flash check for bad blocks first. */
57 + /* Try every possible flash size and check for NVRAM at its end */
58 for (flash_size = FLASH_MIN; flash_size <= res_size; flash_size <<= 1) {
59 - /* Windowed flash access */
60 - size = find_nvram_size(flash_start + flash_size);
62 - offset = flash_size - size;
64 + for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
65 + offset = flash_size - nvram_sizes[i];
66 + if (bcm47xx_nvram_is_valid(flash_start + offset))