1a4a1ec348aa72a80ce14985a09baab5d2fd36a4
[openwrt/staging/noltari.git] /
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
5
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...
11
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.
15
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.
19
20 *) brcmf_fw_request_nvram_done fallback path succeeds or
21 BRCMF_FW_REQF_OPTIONAL is set
22
23 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
24 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
25 ---
26 .../broadcom/brcm80211/brcmfmac/firmware.c | 65 +++++++---------------
27 1 file changed, 19 insertions(+), 46 deletions(-)
28
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;
33 }
34
35 -static int brcmf_fw_request_next_item(struct brcmf_fw *fwctx, bool async)
36 -{
37 - struct brcmf_fw_item *cur;
38 - const struct firmware *fw = NULL;
39 - int ret;
40 -
41 - cur = &fwctx->req->items[fwctx->curpos];
42 -
43 - brcmf_dbg(TRACE, "%srequest for %s\n", async ? "async " : "",
44 - cur->path);
45 -
46 - if (async)
47 - ret = request_firmware_nowait(THIS_MODULE, true, cur->path,
48 - fwctx->dev, GFP_KERNEL, fwctx,
49 - brcmf_fw_request_done);
50 - else
51 - ret = request_firmware(&fw, cur->path, fwctx->dev);
52 -
53 - if (ret < 0) {
54 - brcmf_fw_request_done(NULL, fwctx);
55 - } else if (!async && fw) {
56 - brcmf_fw_complete_request(fw, fwctx);
57 - return -EAGAIN;
58 - }
59 - return 0;
60 -}
61 -
62 static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
63 {
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];
67
68 ret = brcmf_fw_complete_request(fw, fwctx);
69 - if (ret < 0)
70 - goto fail;
71
72 - do {
73 - if (++fwctx->curpos == fwctx->req->n_items) {
74 - ret = 0;
75 - goto done;
76 - }
77 -
78 - ret = brcmf_fw_request_next_item(fwctx, false);
79 - } while (ret == -EAGAIN);
80 -
81 - return;
82 -
83 -fail:
84 - brcmf_dbg(TRACE, "failed err=%d: dev=%s, fw=%s\n", ret,
85 - dev_name(fwctx->dev), cur->path);
86 - brcmf_fw_free_request(fwctx->req);
87 - fwctx->req = NULL;
88 -done:
89 + while (ret == 0 && ++fwctx->curpos < fwctx->req->n_items) {
90 + cur = &fwctx->req->items[fwctx->curpos];
91 + request_firmware(&fw, cur->path, fwctx->dev);
92 + ret = brcmf_fw_complete_request(fw, ctx);
93 + }
94 +
95 + if (ret) {
96 + brcmf_dbg(TRACE, "failed err=%d: dev=%s, fw=%s\n", ret,
97 + dev_name(fwctx->dev), cur->path);
98 + brcmf_fw_free_request(fwctx->req);
99 + fwctx->req = NULL;
100 + }
101 fwctx->done(fwctx->dev, ret, fwctx->req);
102 kfree(fwctx);
103 }
104 @@ -611,7 +577,9 @@ int brcmf_fw_get_firmwares(struct device
105 void (*fw_cb)(struct device *dev, int err,
106 struct brcmf_fw_request *req))
107 {
108 + struct brcmf_fw_item *first = &req->items[0];
109 struct brcmf_fw *fwctx;
110 + int ret;
111
112 brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(dev));
113 if (!fw_cb)
114 @@ -628,7 +596,12 @@ int brcmf_fw_get_firmwares(struct device
115 fwctx->req = req;
116 fwctx->done = fw_cb;
117
118 - brcmf_fw_request_next_item(fwctx, true);
119 + ret = request_firmware_nowait(THIS_MODULE, true, first->path,
120 + fwctx->dev, GFP_KERNEL, fwctx,
121 + brcmf_fw_request_done);
122 + if (ret < 0)
123 + brcmf_fw_request_done(NULL, fwctx);
124 +
125 return 0;
126 }
127