d123252
From 7a2f4b4fa44268a570f6fa7782385741134f8da6 Mon Sep 17 00:00:00 2001
d123252
From: Hans de Goede <hdegoede@redhat.com>
d123252
Date: Thu, 27 Sep 2018 17:51:36 +0200
d123252
Subject: [PATCH 2/5] brcmfmac: Remove recursion from firmware load error
d123252
 handling
d123252
d123252
Before this commit brcmf_fw_request_done would call
d123252
brcmf_fw_request_next_item to load the next item, which on an error would
d123252
call brcmf_fw_request_done, which if the error is recoverable (*) will
d123252
then continue calling brcmf_fw_request_next_item for the next item again
d123252
which on an error will call brcmf_fw_request_done again...
d123252
d123252
This does not blow up because we only have a limited number of items so
d123252
we never recurse too deep. But the recursion is still quite ugly and
d123252
frankly is giving me a headache, so lets fix this.
d123252
d123252
This commit fixes this by removing brcmf_fw_request_next_item and by
d123252
making brcmf_fw_get_firmwares and brcmf_fw_request_done directly call
d123252
firmware_request_nowait resp. firmware_request themselves.
d123252
d123252
*) brcmf_fw_request_nvram_done fallback path succeeds or
d123252
   BRCMF_FW_REQF_OPTIONAL is set
d123252
d123252
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
d123252
---
d123252
 .../broadcom/brcm80211/brcmfmac/firmware.c    | 65 ++++++-------------
d123252
 1 file changed, 19 insertions(+), 46 deletions(-)
d123252
d123252
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
d123252
index 848c3351d107..13d051cd0fcf 100644
d123252
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
d123252
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
d123252
@@ -615,33 +615,6 @@ static int brcmf_fw_complete_request(const struct firmware *fw,
d123252
 	return (cur->flags & BRCMF_FW_REQF_OPTIONAL) ? 0 : ret;
d123252
 }
d123252
 
d123252
-static int brcmf_fw_request_next_item(struct brcmf_fw *fwctx, bool async)
d123252
-{
d123252
-	struct brcmf_fw_item *cur;
d123252
-	const struct firmware *fw = NULL;
d123252
-	int ret;
d123252
-
d123252
-	cur = &fwctx->req->items[fwctx->curpos];
d123252
-
d123252
-	brcmf_dbg(TRACE, "%srequest for %s\n", async ? "async " : "",
d123252
-		  cur->path);
d123252
-
d123252
-	if (async)
d123252
-		ret = request_firmware_nowait(THIS_MODULE, true, cur->path,
d123252
-					      fwctx->dev, GFP_KERNEL, fwctx,
d123252
-					      brcmf_fw_request_done);
d123252
-	else
d123252
-		ret = request_firmware(&fw, cur->path, fwctx->dev);
d123252
-
d123252
-	if (ret < 0) {
d123252
-		brcmf_fw_request_done(NULL, fwctx);
d123252
-	} else if (!async && fw) {
d123252
-		brcmf_fw_complete_request(fw, fwctx);
d123252
-		return -EAGAIN;
d123252
-	}
d123252
-	return 0;
d123252
-}
d123252
-
d123252
 static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
d123252
 {
d123252
 	struct brcmf_fw *fwctx = ctx;
d123252
@@ -651,26 +624,19 @@ static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
d123252
 	cur = &fwctx->req->items[fwctx->curpos];
d123252
 
d123252
 	ret = brcmf_fw_complete_request(fw, fwctx);
d123252
-	if (ret < 0)
d123252
-		goto fail;
d123252
-
d123252
-	do {
d123252
-		if (++fwctx->curpos == fwctx->req->n_items) {
d123252
-			ret = 0;
d123252
-			goto done;
d123252
-		}
d123252
 
d123252
-		ret = brcmf_fw_request_next_item(fwctx, false);
d123252
-	} while (ret == -EAGAIN);
d123252
-
d123252
-	return;
d123252
+	while (ret == 0 && ++fwctx->curpos < fwctx->req->n_items) {
d123252
+		cur = &fwctx->req->items[fwctx->curpos];
d123252
+		request_firmware(&fw, cur->path, fwctx->dev);
d123252
+		ret = brcmf_fw_complete_request(fw, ctx);
d123252
+	}
d123252
 
d123252
-fail:
d123252
-	brcmf_dbg(TRACE, "failed err=%d: dev=%s, fw=%s\n", ret,
d123252
-		  dev_name(fwctx->dev), cur->path);
d123252
-	brcmf_fw_free_request(fwctx->req);
d123252
-	fwctx->req = NULL;
d123252
-done:
d123252
+	if (ret) {
d123252
+		brcmf_dbg(TRACE, "failed err=%d: dev=%s, fw=%s\n", ret,
d123252
+			  dev_name(fwctx->dev), cur->path);
d123252
+		brcmf_fw_free_request(fwctx->req);
d123252
+		fwctx->req = NULL;
d123252
+	}
d123252
 	fwctx->done(fwctx->dev, ret, fwctx->req);
d123252
 	kfree(fwctx);
d123252
 }
d123252
@@ -694,7 +660,9 @@ int brcmf_fw_get_firmwares(struct device *dev, struct brcmf_fw_request *req,
d123252
 			   void (*fw_cb)(struct device *dev, int err,
d123252
 					 struct brcmf_fw_request *req))
d123252
 {
d123252
+	struct brcmf_fw_item *first = &req->items[0];
d123252
 	struct brcmf_fw *fwctx;
d123252
+	int ret;
d123252
 
d123252
 	brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(dev));
d123252
 	if (!fw_cb)
d123252
@@ -711,7 +679,12 @@ int brcmf_fw_get_firmwares(struct device *dev, struct brcmf_fw_request *req,
d123252
 	fwctx->req = req;
d123252
 	fwctx->done = fw_cb;
d123252
 
d123252
-	brcmf_fw_request_next_item(fwctx, true);
d123252
+	ret = request_firmware_nowait(THIS_MODULE, true, first->path,
d123252
+				      fwctx->dev, GFP_KERNEL, fwctx,
d123252
+				      brcmf_fw_request_done);
d123252
+	if (ret < 0)
d123252
+		brcmf_fw_request_done(NULL, fwctx);
d123252
+
d123252
 	return 0;
d123252
 }
d123252
 
d123252
-- 
d123252
2.19.0
d123252