065543184f77d3840eb218ff257b2bcdc058c74a
[openwrt/staging/jogo.git] /
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
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
11 returning NVRAM size.
12
13 The new code always operates on offsets which means less logic and less
14 calculations.
15
16 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
17 Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
18 ---
19 drivers/firmware/broadcom/bcm47xx_nvram.c | 25 +++++++----------------
20 1 file changed, 7 insertions(+), 18 deletions(-)
21
22 diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c
23 index 1d2271b1e07a..bd235833b687 100644
24 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c
25 +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c
26 @@ -42,18 +42,6 @@ static bool bcm47xx_nvram_is_valid(void __iomem *nvram)
27 return ((struct nvram_header *)nvram)->magic == NVRAM_MAGIC;
28 }
29
30 -static u32 find_nvram_size(void __iomem *end)
31 -{
32 - int i;
33 -
34 - for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
35 - if (bcm47xx_nvram_is_valid(end - nvram_sizes[i]))
36 - return nvram_sizes[i];
37 - }
38 -
39 - return 0;
40 -}
41 -
42 /**
43 * bcm47xx_nvram_copy - copy NVRAM to internal buffer
44 */
45 @@ -85,7 +73,7 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz
46 {
47 size_t flash_size;
48 size_t offset;
49 - u32 size;
50 + int i;
51
52 if (nvram_len) {
53 pr_warn("nvram already initialized\n");
54 @@ -93,12 +81,13 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz
55 }
56
57 /* TODO: when nvram is on nand flash check for bad blocks first. */
58 +
59 + /* Try every possible flash size and check for NVRAM at its end */
60 for (flash_size = FLASH_MIN; flash_size <= res_size; flash_size <<= 1) {
61 - /* Windowed flash access */
62 - size = find_nvram_size(flash_start + flash_size);
63 - if (size) {
64 - offset = flash_size - size;
65 - goto found;
66 + for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
67 + offset = flash_size - nvram_sizes[i];
68 + if (bcm47xx_nvram_is_valid(flash_start + offset))
69 + goto found;
70 }
71 }
72
73 --
74 2.26.2
75