21d250049e6f6cfc439f28a687ce09005b0f9b0f
[openwrt/staging/mans0n.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 --- 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;
26 }
27
28 -static u32 find_nvram_size(void __iomem *end)
29 -{
30 - int i;
31 -
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];
35 - }
36 -
37 - return 0;
38 -}
39 -
40 /**
41 * bcm47xx_nvram_copy - copy NVRAM to internal buffer
42 */
43 @@ -85,7 +73,7 @@ static int bcm47xx_nvram_find_and_copy(v
44 {
45 size_t flash_size;
46 size_t offset;
47 - u32 size;
48 + int i;
49
50 if (nvram_len) {
51 pr_warn("nvram already initialized\n");
52 @@ -93,12 +81,13 @@ static int bcm47xx_nvram_find_and_copy(v
53 }
54
55 /* TODO: when nvram is on nand flash check for bad blocks first. */
56 +
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);
61 - if (size) {
62 - offset = flash_size - size;
63 - goto found;
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))
67 + goto found;
68 }
69 }
70