Commit bec2dd69 authored by Kees Cook's avatar Kees Cook Committed by Rob Clark

drm/msm/adreno: Remove VLA usage

In the quest to remove all stack VLA usage from the kernel[1], this
switches to using a kasprintf()ed buffer. Return paths are updated
to free the allocation.

[1] https://lkml.kernel.org/r/CA+55aFzCG-zNmZwX4A2FQpadafLfEzK6CC=qPXydAacU1RqZWA@mail.gmail.comSigned-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarRob Clark <robdclark@gmail.com>
parent a5f74ec7
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
* *
*/ */
#include <linux/kernel.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/qcom_scm.h> #include <linux/qcom_scm.h>
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
#include <linux/pm_opp.h> #include <linux/pm_opp.h>
#include <linux/nvmem-consumer.h> #include <linux/nvmem-consumer.h>
#include <linux/iopoll.h> #include <linux/iopoll.h>
#include <linux/slab.h>
#include "msm_gem.h" #include "msm_gem.h"
#include "msm_mmu.h" #include "msm_mmu.h"
#include "a5xx_gpu.h" #include "a5xx_gpu.h"
...@@ -92,12 +94,13 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname) ...@@ -92,12 +94,13 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname)
ret = qcom_mdt_load(dev, fw, fwname, GPU_PAS_ID, ret = qcom_mdt_load(dev, fw, fwname, GPU_PAS_ID,
mem_region, mem_phys, mem_size, NULL); mem_region, mem_phys, mem_size, NULL);
} else { } else {
char newname[strlen("qcom/") + strlen(fwname) + 1]; char *newname;
sprintf(newname, "qcom/%s", fwname); newname = kasprintf(GFP_KERNEL, "qcom/%s", fwname);
ret = qcom_mdt_load(dev, fw, newname, GPU_PAS_ID, ret = qcom_mdt_load(dev, fw, newname, GPU_PAS_ID,
mem_region, mem_phys, mem_size, NULL); mem_region, mem_phys, mem_size, NULL);
kfree(newname);
} }
if (ret) if (ret)
goto out; goto out;
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
*/ */
#include <linux/ascii85.h> #include <linux/ascii85.h>
#include <linux/kernel.h>
#include <linux/pm_opp.h> #include <linux/pm_opp.h>
#include <linux/slab.h>
#include "adreno_gpu.h" #include "adreno_gpu.h"
#include "msm_gem.h" #include "msm_gem.h"
#include "msm_mmu.h" #include "msm_mmu.h"
...@@ -71,10 +73,12 @@ adreno_request_fw(struct adreno_gpu *adreno_gpu, const char *fwname) ...@@ -71,10 +73,12 @@ adreno_request_fw(struct adreno_gpu *adreno_gpu, const char *fwname)
{ {
struct drm_device *drm = adreno_gpu->base.dev; struct drm_device *drm = adreno_gpu->base.dev;
const struct firmware *fw = NULL; const struct firmware *fw = NULL;
char newname[strlen("qcom/") + strlen(fwname) + 1]; char *newname;
int ret; int ret;
sprintf(newname, "qcom/%s", fwname); newname = kasprintf(GFP_KERNEL, "qcom/%s", fwname);
if (!newname)
return ERR_PTR(-ENOMEM);
/* /*
* Try first to load from qcom/$fwfile using a direct load (to avoid * Try first to load from qcom/$fwfile using a direct load (to avoid
...@@ -88,11 +92,12 @@ adreno_request_fw(struct adreno_gpu *adreno_gpu, const char *fwname) ...@@ -88,11 +92,12 @@ adreno_request_fw(struct adreno_gpu *adreno_gpu, const char *fwname)
dev_info(drm->dev, "loaded %s from new location\n", dev_info(drm->dev, "loaded %s from new location\n",
newname); newname);
adreno_gpu->fwloc = FW_LOCATION_NEW; adreno_gpu->fwloc = FW_LOCATION_NEW;
return fw; goto out;
} else if (adreno_gpu->fwloc != FW_LOCATION_UNKNOWN) { } else if (adreno_gpu->fwloc != FW_LOCATION_UNKNOWN) {
dev_err(drm->dev, "failed to load %s: %d\n", dev_err(drm->dev, "failed to load %s: %d\n",
newname, ret); newname, ret);
return ERR_PTR(ret); fw = ERR_PTR(ret);
goto out;
} }
} }
...@@ -107,11 +112,12 @@ adreno_request_fw(struct adreno_gpu *adreno_gpu, const char *fwname) ...@@ -107,11 +112,12 @@ adreno_request_fw(struct adreno_gpu *adreno_gpu, const char *fwname)
dev_info(drm->dev, "loaded %s from legacy location\n", dev_info(drm->dev, "loaded %s from legacy location\n",
newname); newname);
adreno_gpu->fwloc = FW_LOCATION_LEGACY; adreno_gpu->fwloc = FW_LOCATION_LEGACY;
return fw; goto out;
} else if (adreno_gpu->fwloc != FW_LOCATION_UNKNOWN) { } else if (adreno_gpu->fwloc != FW_LOCATION_UNKNOWN) {
dev_err(drm->dev, "failed to load %s: %d\n", dev_err(drm->dev, "failed to load %s: %d\n",
fwname, ret); fwname, ret);
return ERR_PTR(ret); fw = ERR_PTR(ret);
goto out;
} }
} }
...@@ -127,16 +133,20 @@ adreno_request_fw(struct adreno_gpu *adreno_gpu, const char *fwname) ...@@ -127,16 +133,20 @@ adreno_request_fw(struct adreno_gpu *adreno_gpu, const char *fwname)
dev_info(drm->dev, "loaded %s with helper\n", dev_info(drm->dev, "loaded %s with helper\n",
newname); newname);
adreno_gpu->fwloc = FW_LOCATION_HELPER; adreno_gpu->fwloc = FW_LOCATION_HELPER;
return fw; goto out;
} else if (adreno_gpu->fwloc != FW_LOCATION_UNKNOWN) { } else if (adreno_gpu->fwloc != FW_LOCATION_UNKNOWN) {
dev_err(drm->dev, "failed to load %s: %d\n", dev_err(drm->dev, "failed to load %s: %d\n",
newname, ret); newname, ret);
return ERR_PTR(ret); fw = ERR_PTR(ret);
goto out;
} }
} }
dev_err(drm->dev, "failed to load %s\n", fwname); dev_err(drm->dev, "failed to load %s\n", fwname);
return ERR_PTR(-ENOENT); fw = ERR_PTR(-ENOENT);
out:
kfree(newname);
return fw;
} }
static int adreno_load_fw(struct adreno_gpu *adreno_gpu) static int adreno_load_fw(struct adreno_gpu *adreno_gpu)
......
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