lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210308090320.9765-6-zajec5@gmail.com>
Date:   Mon,  8 Mar 2021 10:03:20 +0100
From:   Rafał Miłecki <zajec5@...il.com>
To:     Thomas Bogendoerfer <tsbogend@...ha.franken.de>
Cc:     linux-mips@...r.kernel.org,
        Florian Fainelli <f.fainelli@...il.com>,
        Vivek Unune <npcomplete13@...il.com>,
        bcm-kernel-feedback-list@...adcom.com,
        linux-kernel@...r.kernel.org,
        Philippe Mathieu-Daudé <f4bug@...at.org>,
        Rafał Miłecki <rafal@...ecki.pl>
Subject: [PATCH  mips/linux.git 5/5] firmware: bcm47xx_nvram: inline code checking NVRAM size

From: Rafał Miłecki <rafal@...ecki.pl>

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@...ecki.pl>
---
 drivers/firmware/broadcom/bcm47xx_nvram.c | 25 +++++++----------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c
index 1d2271b1e07a..bd235833b687 100644
--- a/drivers/firmware/broadcom/bcm47xx_nvram.c
+++ b/drivers/firmware/broadcom/bcm47xx_nvram.c
@@ -42,18 +42,6 @@ static bool bcm47xx_nvram_is_valid(void __iomem *nvram)
 	return ((struct nvram_header *)nvram)->magic == NVRAM_MAGIC;
 }
 
-static u32 find_nvram_size(void __iomem *end)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
-		if (bcm47xx_nvram_is_valid(end - nvram_sizes[i]))
-			return nvram_sizes[i];
-	}
-
-	return 0;
-}
-
 /**
  * bcm47xx_nvram_copy - copy NVRAM to internal buffer
  */
@@ -85,7 +73,7 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz
 {
 	size_t flash_size;
 	size_t offset;
-	u32 size;
+	int i;
 
 	if (nvram_len) {
 		pr_warn("nvram already initialized\n");
@@ -93,12 +81,13 @@ static int bcm47xx_nvram_find_and_copy(void __iomem *flash_start, size_t res_siz
 	}
 
 	/* TODO: when nvram is on nand flash check for bad blocks first. */
+
+	/* Try every possible flash size and check for NVRAM at its end */
 	for (flash_size = FLASH_MIN; flash_size <= res_size; flash_size <<= 1) {
-		/* Windowed flash access */
-		size = find_nvram_size(flash_start + flash_size);
-		if (size) {
-			offset = flash_size - size;
-			goto found;
+		for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
+			offset = flash_size - nvram_sizes[i];
+			if (bcm47xx_nvram_is_valid(flash_start + offset))
+				goto found;
 		}
 	}
 
-- 
2.26.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ