1 From 5b587496dc63595b71265d986ce69728c2724370 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Wed, 10 Oct 2018 13:00:59 +0200
4 Subject: [PATCH] brcmfmac: Remove recursion from firmware load error handling
6 Before this commit brcmf_fw_request_done would call
7 brcmf_fw_request_next_item to load the next item, which on an error would
8 call brcmf_fw_request_done, which if the error is recoverable (*) will
9 then continue calling brcmf_fw_request_next_item for the next item again
10 which on an error will call brcmf_fw_request_done again...
12 This does not blow up because we only have a limited number of items so
13 we never recurse too deep. But the recursion is still quite ugly and
14 frankly is giving me a headache, so lets fix this.
16 This commit fixes this by removing brcmf_fw_request_next_item and by
17 making brcmf_fw_get_firmwares and brcmf_fw_request_done directly call
18 firmware_request_nowait resp. firmware_request themselves.
20 *) brcmf_fw_request_nvram_done fallback path succeeds or
21 BRCMF_FW_REQF_OPTIONAL is set
23 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
24 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
26 .../broadcom/brcm80211/brcmfmac/firmware.c | 65 +++++++---------------
27 1 file changed, 19 insertions(+), 46 deletions(-)
29 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
30 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
31 @@ -532,33 +532,6 @@ static int brcmf_fw_complete_request(con
32 return (cur->flags & BRCMF_FW_REQF_OPTIONAL) ? 0 : ret;
35 -static int brcmf_fw_request_next_item(struct brcmf_fw *fwctx, bool async)
37 - struct brcmf_fw_item *cur;
38 - const struct firmware *fw = NULL;
41 - cur = &fwctx->req->items[fwctx->curpos];
43 - brcmf_dbg(TRACE, "%srequest for %s\n", async ? "async " : "",
47 - ret = request_firmware_nowait(THIS_MODULE, true, cur->path,
48 - fwctx->dev, GFP_KERNEL, fwctx,
49 - brcmf_fw_request_done);
51 - ret = request_firmware(&fw, cur->path, fwctx->dev);
54 - brcmf_fw_request_done(NULL, fwctx);
55 - } else if (!async && fw) {
56 - brcmf_fw_complete_request(fw, fwctx);
62 static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
64 struct brcmf_fw *fwctx = ctx;
65 @@ -568,26 +541,19 @@ static void brcmf_fw_request_done(const
66 cur = &fwctx->req->items[fwctx->curpos];
68 ret = brcmf_fw_complete_request(fw, fwctx);
73 - if (++fwctx->curpos == fwctx->req->n_items) {
78 - ret = brcmf_fw_request_next_item(fwctx, false);
79 - } while (ret == -EAGAIN);
82 + while (ret == 0 && ++fwctx->curpos < fwctx->req->n_items) {
83 + cur = &fwctx->req->items[fwctx->curpos];
84 + request_firmware(&fw, cur->path, fwctx->dev);
85 + ret = brcmf_fw_complete_request(fw, ctx);
89 - brcmf_dbg(TRACE, "failed err=%d: dev=%s, fw=%s\n", ret,
90 - dev_name(fwctx->dev), cur->path);
91 - brcmf_fw_free_request(fwctx->req);
95 + brcmf_dbg(TRACE, "failed err=%d: dev=%s, fw=%s\n", ret,
96 + dev_name(fwctx->dev), cur->path);
97 + brcmf_fw_free_request(fwctx->req);
100 fwctx->done(fwctx->dev, ret, fwctx->req);
103 @@ -611,7 +577,9 @@ int brcmf_fw_get_firmwares(struct device
104 void (*fw_cb)(struct device *dev, int err,
105 struct brcmf_fw_request *req))
107 + struct brcmf_fw_item *first = &req->items[0];
108 struct brcmf_fw *fwctx;
111 brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(dev));
113 @@ -628,7 +596,12 @@ int brcmf_fw_get_firmwares(struct device
117 - brcmf_fw_request_next_item(fwctx, true);
118 + ret = request_firmware_nowait(THIS_MODULE, true, first->path,
119 + fwctx->dev, GFP_KERNEL, fwctx,
120 + brcmf_fw_request_done);
122 + brcmf_fw_request_done(NULL, fwctx);