eca15a516e5bf17a0641114dd44fac0e24dc6d72
[openwrt/staging/yousong.git] /
1 From a1a3b762163868ad07a4499a73df324f40d5ab0b Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Wed, 10 Oct 2018 13:00:58 +0200
4 Subject: [PATCH] brcmfmac: Remove firmware-loading code duplication
5
6 brcmf_fw_request_next_item and brcmf_fw_request_done both have identical
7 code to complete the fw-request depending on the item-type.
8
9 This commit adds a new brcmf_fw_complete_request helper removing this code
10 duplication.
11
12 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
13 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
14 ---
15 .../broadcom/brcm80211/brcmfmac/firmware.c | 62 +++++++++++-----------
16 1 file changed, 31 insertions(+), 31 deletions(-)
17
18 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
19 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/firmware.c
20 @@ -504,6 +504,34 @@ fail:
21 return -ENOENT;
22 }
23
24 +static int brcmf_fw_complete_request(const struct firmware *fw,
25 + struct brcmf_fw *fwctx)
26 +{
27 + struct brcmf_fw_item *cur = &fwctx->req->items[fwctx->curpos];
28 + int ret = 0;
29 +
30 + brcmf_dbg(TRACE, "firmware %s %sfound\n", cur->path, fw ? "" : "not ");
31 +
32 + switch (cur->type) {
33 + case BRCMF_FW_TYPE_NVRAM:
34 + ret = brcmf_fw_request_nvram_done(fw, fwctx);
35 + break;
36 + case BRCMF_FW_TYPE_BINARY:
37 + if (fw)
38 + cur->binary = fw;
39 + else
40 + ret = -ENOENT;
41 + break;
42 + default:
43 + /* something fishy here so bail out early */
44 + brcmf_err("unknown fw type: %d\n", cur->type);
45 + release_firmware(fw);
46 + ret = -EINVAL;
47 + }
48 +
49 + return (cur->flags & BRCMF_FW_REQF_OPTIONAL) ? 0 : ret;
50 +}
51 +
52 static int brcmf_fw_request_next_item(struct brcmf_fw *fwctx, bool async)
53 {
54 struct brcmf_fw_item *cur;
55 @@ -525,15 +553,7 @@ static int brcmf_fw_request_next_item(st
56 if (ret < 0) {
57 brcmf_fw_request_done(NULL, fwctx);
58 } else if (!async && fw) {
59 - brcmf_dbg(TRACE, "firmware %s %sfound\n", cur->path,
60 - fw ? "" : "not ");
61 - if (cur->type == BRCMF_FW_TYPE_BINARY)
62 - cur->binary = fw;
63 - else if (cur->type == BRCMF_FW_TYPE_NVRAM)
64 - brcmf_fw_request_nvram_done(fw, fwctx);
65 - else
66 - release_firmware(fw);
67 -
68 + brcmf_fw_complete_request(fw, fwctx);
69 return -EAGAIN;
70 }
71 return 0;
72 @@ -547,28 +567,8 @@ static void brcmf_fw_request_done(const
73
74 cur = &fwctx->req->items[fwctx->curpos];
75
76 - brcmf_dbg(TRACE, "enter: firmware %s %sfound\n", cur->path,
77 - fw ? "" : "not ");
78 -
79 - if (!fw)
80 - ret = -ENOENT;
81 -
82 - switch (cur->type) {
83 - case BRCMF_FW_TYPE_NVRAM:
84 - ret = brcmf_fw_request_nvram_done(fw, fwctx);
85 - break;
86 - case BRCMF_FW_TYPE_BINARY:
87 - cur->binary = fw;
88 - break;
89 - default:
90 - /* something fishy here so bail out early */
91 - brcmf_err("unknown fw type: %d\n", cur->type);
92 - release_firmware(fw);
93 - ret = -EINVAL;
94 - goto fail;
95 - }
96 -
97 - if (ret < 0 && !(cur->flags & BRCMF_FW_REQF_OPTIONAL))
98 + ret = brcmf_fw_complete_request(fw, fwctx);
99 + if (ret < 0)
100 goto fail;
101
102 do {