Skip to contentSkip to conversation

drm/msm/adreno: Ensure that the zap shader region is big enough

PATCH In review Jordan Crouse 3 participants 3 messages May 31, 2019 – Jun 3, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/msm/adreno: Ensure that the zap shader region is big enough

Before loading the zap shader we should ensure that the reserved memory region is big enough to hold the loaded file.

---

 drivers/gpu/drm/msm/adreno/adreno_gpu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +7 -1
index 6f7f411..3db8e49 100644
@@ -67,7 +67,6 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
 		return ret;
 
 	mem_phys = r.start;
-	mem_size = resource_size(&r);
 
 	/* Request the MDT file for the firmware */
 	fw = adreno_request_fw(to_adreno_gpu(gpu), fwname);
@@ -83,6 +82,13 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
 		goto out;
 	}
 
+	if (mem_size > resource_size(&r)) {
+		DRM_DEV_ERROR(dev,
+			"memory region is too small to load the MDT\n");
+		ret = -E2BIG;
+		goto out;
+	}
+
 	/* Allocate memory for the firmware image */
 	mem_region = memremap(mem_phys, mem_size,  MEMREMAP_WC);
 	if (!mem_region) {
Signature · 6 lines
2.7.4

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Jordan Crouse

Before loading the zap shader we should ensure that the reserved memory region is big enough to hold the loaded file.

Quoted 34 lines

---

 drivers/gpu/drm/msm/adreno/adreno_gpu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +7 -1
index 6f7f411..3db8e49 100644
@@ -67,7 +67,6 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
 		return ret;
 
 	mem_phys = r.start;
-	mem_size = resource_size(&r);
 
 	/* Request the MDT file for the firmware */
 	fw = adreno_request_fw(to_adreno_gpu(gpu), fwname);
@@ -83,6 +82,13 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
 		goto out;
 	}
 
+	if (mem_size > resource_size(&r)) {
+		DRM_DEV_ERROR(dev,
+			"memory region is too small to load the MDT\n");
+		ret = -E2BIG;
+		goto out;
+	}
+
 	/* Allocate memory for the firmware image */
 	mem_region = memremap(mem_phys, mem_size,  MEMREMAP_WC);
 	if (!mem_region) {
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#2 lore raw
In reply to Jordan Crouse
Quoted 5 lines · Jordan Crouse

Before loading the zap shader we should ensure that the reserved memory region is big enough to hold the loaded file.

Quoted 34 lines

---

 drivers/gpu/drm/msm/adreno/adreno_gpu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +7 -2
index 6f7f411..3db8e49 100644
@@ -67,7 +67,6 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
                return ret;
 
        mem_phys = r.start;
-       mem_size = resource_size(&r);
 
        /* Request the MDT file for the firmware */
        fw = adreno_request_fw(to_adreno_gpu(gpu), fwname);
@@ -83,6 +82,13 @@ static int zap_shader_load_mdt(struct msm_gpu *gpu, const char *fwname,
                goto out;
        }
 
+       if (mem_size > resource_size(&r)) {
+               DRM_DEV_ERROR(dev,
+                       "memory region is too small to load the MDT\n");
+               ret = -E2BIG;
+               goto out;
+       }
+
        /* Allocate memory for the firmware image */
        mem_region = memremap(mem_phys, mem_size,  MEMREMAP_WC);
        if (!mem_region) {
--

2.7.4

Quoted 4 lines

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno