All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] brcmfmac: simplify check finding NVRAM v1 device path
@ 2015-05-20  9:01 Rafał Miłecki
  2015-05-28  8:50 ` Kalle Valo
  0 siblings, 1 reply; 2+ messages in thread
From: Rafał Miłecki @ 2015-05-20  9:01 UTC (permalink / raw)
  To: Kalle Valo, linux-wireless
  Cc: Brett Rudley, Arend van Spriel, Franky (Zhenhui) Lin,
	Hante Meuleman, brcm80211-dev-list, Rafał Miłecki

With a simple use of snprintf and small buffer we can compare NVRAM
entry value with a full string. This way we avoid checking random chars
at magic offsets.
Tested on BCM43602 with NVRAM hacked to use v1 format.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
---
 drivers/net/wireless/brcm80211/brcmfmac/firmware.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
index 181a0e8..0d02e31 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
@@ -222,6 +222,10 @@ static int brcmf_init_nvram_parser(struct nvram_parser *nvp,
 static void brcmf_fw_strip_multi_v1(struct nvram_parser *nvp, u16 domain_nr,
 				    u16 bus_nr)
 {
+	/* Device path with a leading '=' key-value separator */
+	char pcie_path[] = "=pcie/?/?";
+	size_t pcie_len;
+
 	u32 i, j;
 	bool found;
 	u8 *nvram;
@@ -238,6 +242,9 @@ static void brcmf_fw_strip_multi_v1(struct nvram_parser *nvp, u16 domain_nr,
 	/* First search for the devpathX and see if it is the configuration
 	 * for domain_nr/bus_nr. Search complete nvp
 	 */
+	snprintf(pcie_path, sizeof(pcie_path), "=pcie/%d/%d", domain_nr,
+		 bus_nr);
+	pcie_len = strlen(pcie_path);
 	found = false;
 	i = 0;
 	while (i < nvp->nvram_len - BRCMF_FW_NVRAM_DEVPATH_LEN) {
@@ -245,13 +252,10 @@ static void brcmf_fw_strip_multi_v1(struct nvram_parser *nvp, u16 domain_nr,
 		 * Y = domain_nr, Z = bus_nr, X = virtual ID
 		 */
 		if ((strncmp(&nvp->nvram[i], "devpath", 7) == 0) &&
-		    (strncmp(&nvp->nvram[i + 8], "=pcie/", 6) == 0)) {
-			if (((nvp->nvram[i + 14] - '0') == domain_nr) &&
-			    ((nvp->nvram[i + 16] - '0') == bus_nr)) {
-				id = nvp->nvram[i + 7] - '0';
-				found = true;
-				break;
-			}
+		    (strncmp(&nvp->nvram[i + 8], pcie_path, pcie_len) == 0)) {
+			id = nvp->nvram[i + 7] - '0';
+			found = true;
+			break;
 		}
 		while (nvp->nvram[i] != 0)
 			i++;
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] brcmfmac: simplify check finding NVRAM v1 device path
  2015-05-20  9:01 [PATCH] brcmfmac: simplify check finding NVRAM v1 device path Rafał Miłecki
@ 2015-05-28  8:50 ` Kalle Valo
  0 siblings, 0 replies; 2+ messages in thread
From: Kalle Valo @ 2015-05-28  8:50 UTC (permalink / raw)
  To: Rafał Miłecki
  Cc: linux-wireless, Brett Rudley, Arend van Spriel,
	Franky (Zhenhui) Lin, Hante Meuleman, brcm80211-dev-list

Rafał Miłecki <zajec5@gmail.com> writes:

> With a simple use of snprintf and small buffer we can compare NVRAM
> entry value with a full string. This way we avoid checking random chars
> at magic offsets.
> Tested on BCM43602 with NVRAM hacked to use v1 format.
>
> Signed-off-by: Rafał Miłecki <zajec5@gmail.com>

Thanks, applied manually.

-- 
Kalle Valo

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-05-28  8:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-20  9:01 [PATCH] brcmfmac: simplify check finding NVRAM v1 device path Rafał Miłecki
2015-05-28  8:50 ` Kalle Valo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.