Skip to contentSkip to conversation

drm/msm: remove some dead code

PATCH Applied Dan Carpenter 2 participants 3 messages Jan 8 – Jan 15

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

PATCH 1/1 drm/msm: remove some dead code

This is supposed to test for integer overflow but it is wrong and unnecessary. The size_add()/mul() macros return SIZE_MAX when there is an integer overflow. This code saves the SIZE_MAX to a u64 and then tests if the result is greater than SIZE_MAX which it never will be. Fortunately, when we try to allocate SIZE_MAX bytes the allocation will fail. We even pass __GFP_NOWARN so the allocation fails harmlessly and quietly.

---
 drivers/gpu/drm/msm/msm_gem_vma.c | 8 +-------
 1 file changed, 1 insertions(+), 7 deletions(-)
drivers/gpu/drm/msm/msm_gem_vma.c +1 -7
index 71d5238437eb..7968c2dccff0 100644
@@ -947,15 +947,9 @@ vm_bind_job_create(struct drm_device *dev, struct drm_file *file,
 		   struct msm_gpu_submitqueue *queue, uint32_t nr_ops)
 {
 	struct msm_vm_bind_job *job;
-	uint64_t sz;
 	int ret;
 
-	sz = struct_size(job, ops, nr_ops);
-
-	if (sz > SIZE_MAX)
-		return ERR_PTR(-ENOMEM);
-
-	job = kzalloc(sz, GFP_KERNEL | __GFP_NOWARN);
+	job = kzalloc(struct_size(job, ops, nr_ops), GFP_KERNEL | __GFP_NOWARN);
 	if (!job)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dan Carpenter

This is supposed to test for integer overflow but it is wrong and unnecessary. The size_add()/mul() macros return SIZE_MAX when there is an integer overflow. This code saves the SIZE_MAX to a u64 and then tests if the result is greater than SIZE_MAX which it never will be. Fortunately, when we try to allocate SIZE_MAX bytes the allocation will fail. We even pass __GFP_NOWARN so the allocation fails harmlessly and quietly.

Quoted 4 lines
---
 drivers/gpu/drm/msm/msm_gem_vma.c | 8 +-------
 1 file changed, 1 insertions(+), 7 deletions(-)
Fixes 2e6a8a1fe2b2 ("drm/msm: Add VM_BIND ioctl")
Signature · 2 lines
With best wishes
Dmitry
#2 lore raw
In reply to Dan Carpenter
Quoted 9 lines · Dan Carpenter

This is supposed to test for integer overflow but it is wrong and unnecessary. The size_add()/mul() macros return SIZE_MAX when there is an integer overflow. This code saves the SIZE_MAX to a u64 and then tests if the result is greater than SIZE_MAX which it never will be. Fortunately, when we try to allocate SIZE_MAX bytes the allocation will fail. We even pass __GFP_NOWARN so the allocation fails harmlessly and quietly.

[...]

Applied to msm-next, thanks!

[1/1] drm/msm: remove some dead code

      https://gitlab.freedesktop.org/lumag/msm/-/commit/37d2e108de4d

Best regards,

Signature · 2 lines
With best wishes
Dmitry