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 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;
30 -static u32 find_nvram_size(void __iomem *end)
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];
43 * bcm47xx_nvram_copy - copy NVRAM to internal buffer
45 @@ -85,7 +73,7 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz
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
57 /* TODO: when nvram is on nand flash check for bad blocks first. */
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);
64 - offset = flash_size - size;
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))