remoteproc: qcom: mdt_loader: Don't overwrite firmware object
authorBjorn Andersson <bjorn.andersson@linaro.org>
Fri, 27 Jan 2017 10:06:36 +0000 (02:06 -0800)
committerBjorn Andersson <bjorn.andersson@linaro.org>
Mon, 6 Feb 2017 16:57:24 +0000 (08:57 -0800)
The "fw" firmware object is passed from the remoteproc core and should
not be overwritten, as that results in leaked buffers and a double free
of the the last firmware object.

Fixes: 051fb70fd4ea ("remoteproc: qcom: Driver for the self-authenticating Hexagon v5")
Cc: stable@vger.kernel.org
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
drivers/remoteproc/qcom_mdt_loader.c

index 897e14512123b571a6e04ac4fe64d1408e36bafa..fe7d5207ad17490ab6d0fc055911bbfb32b5be8e 100644 (file)
@@ -97,6 +97,7 @@ int qcom_mdt_load(struct rproc *rproc,
        const struct elf32_phdr *phdrs;
        const struct elf32_phdr *phdr;
        const struct elf32_hdr *ehdr;
+       const struct firmware *seg_fw;
        size_t fw_name_len;
        char *fw_name;
        void *ptr;
@@ -135,16 +136,16 @@ int qcom_mdt_load(struct rproc *rproc,
 
                if (phdr->p_filesz) {
                        sprintf(fw_name + fw_name_len - 3, "b%02d", i);
-                       ret = request_firmware(&fw, fw_name, &rproc->dev);
+                       ret = request_firmware(&seg_fw, fw_name, &rproc->dev);
                        if (ret) {
                                dev_err(&rproc->dev, "failed to load %s\n",
                                        fw_name);
                                break;
                        }
 
-                       memcpy(ptr, fw->data, fw->size);
+                       memcpy(ptr, seg_fw->data, seg_fw->size);
 
-                       release_firmware(fw);
+                       release_firmware(seg_fw);
                }
 
                if (phdr->p_memsz > phdr->p_filesz)