Commit 0b5c0305 authored by Arend Van Spriel's avatar Arend Van Spriel Committed by Kalle Valo

brcmfmac: fix firmware request processing if nvram load fails

When nvram loading fails a double free occurred. Fix this and reorg the
code a little.

Fixes: d09ae51a ("brcmfmac: pass struct in brcmf_fw_get_firmwares()")
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarArend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent 4608f064
...@@ -459,7 +459,7 @@ static void brcmf_fw_free_request(struct brcmf_fw_request *req) ...@@ -459,7 +459,7 @@ static void brcmf_fw_free_request(struct brcmf_fw_request *req)
kfree(req); kfree(req);
} }
static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx) static int brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx)
{ {
struct brcmf_fw *fwctx = ctx; struct brcmf_fw *fwctx = ctx;
struct brcmf_fw_item *cur; struct brcmf_fw_item *cur;
...@@ -498,13 +498,10 @@ static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx) ...@@ -498,13 +498,10 @@ static void brcmf_fw_request_nvram_done(const struct firmware *fw, void *ctx)
brcmf_dbg(TRACE, "nvram %p len %d\n", nvram, nvram_length); brcmf_dbg(TRACE, "nvram %p len %d\n", nvram, nvram_length);
cur->nv_data.data = nvram; cur->nv_data.data = nvram;
cur->nv_data.len = nvram_length; cur->nv_data.len = nvram_length;
return; return 0;
fail: fail:
brcmf_dbg(TRACE, "failed: dev=%s\n", dev_name(fwctx->dev)); return -ENOENT;
fwctx->done(fwctx->dev, -ENOENT, NULL);
brcmf_fw_free_request(fwctx->req);
kfree(fwctx);
} }
static int brcmf_fw_request_next_item(struct brcmf_fw *fwctx, bool async) static int brcmf_fw_request_next_item(struct brcmf_fw *fwctx, bool async)
...@@ -553,20 +550,27 @@ static void brcmf_fw_request_done(const struct firmware *fw, void *ctx) ...@@ -553,20 +550,27 @@ static void brcmf_fw_request_done(const struct firmware *fw, void *ctx)
brcmf_dbg(TRACE, "enter: firmware %s %sfound\n", cur->path, brcmf_dbg(TRACE, "enter: firmware %s %sfound\n", cur->path,
fw ? "" : "not "); fw ? "" : "not ");
if (fw) { if (!fw)
if (cur->type == BRCMF_FW_TYPE_BINARY) ret = -ENOENT;
switch (cur->type) {
case BRCMF_FW_TYPE_NVRAM:
ret = brcmf_fw_request_nvram_done(fw, fwctx);
break;
case BRCMF_FW_TYPE_BINARY:
cur->binary = fw; cur->binary = fw;
else if (cur->type == BRCMF_FW_TYPE_NVRAM) break;
brcmf_fw_request_nvram_done(fw, fwctx); default:
else /* something fishy here so bail out early */
brcmf_err("unknown fw type: %d\n", cur->type);
release_firmware(fw); release_firmware(fw);
} else if (cur->type == BRCMF_FW_TYPE_NVRAM) { ret = -EINVAL;
brcmf_fw_request_nvram_done(NULL, fwctx);
} else if (!(cur->flags & BRCMF_FW_REQF_OPTIONAL)) {
ret = -ENOENT;
goto fail; goto fail;
} }
if (ret < 0 && !(cur->flags & BRCMF_FW_REQF_OPTIONAL))
goto fail;
do { do {
if (++fwctx->curpos == fwctx->req->n_items) { if (++fwctx->curpos == fwctx->req->n_items) {
ret = 0; ret = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment