f3da1df54113a9ce8568d427414ccf495f4e0b40
[openwrt/staging/aparcar.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 + 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);
86 + }
87
88 -fail:
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);
92 - fwctx->req = NULL;
93 -done:
94 + if (ret) {
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);
98 + fwctx->req = NULL;
99 + }
100 fwctx->done(fwctx->dev, ret, fwctx->req);
101 kfree(fwctx);
102 }
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))
106 {
107 + struct brcmf_fw_item *first = &req->items[0];
108 struct brcmf_fw *fwctx;
109 + int ret;
110
111 brcmf_dbg(TRACE, "enter: dev=%s\n", dev_name(dev));
112 if (!fw_cb)
113 @@ -628,7 +596,12 @@ int brcmf_fw_get_firmwares(struct device
114 fwctx->req = req;
115 fwctx->done = fw_cb;
116
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);
121 + if (ret < 0)
122 + brcmf_fw_request_done(NULL, fwctx);
123 +
124 return 0;
125 }
126