Skip to contentSkip to conversation

gpu: drm: dead code elimination

PATCH Applied Pan Zhang 3 participants 4 messages Dec 18, 2019 – Dec 19, 2019

Subsystems (2)
lore
Share & tools
lore

Pan Zhang

author
#0 lore raw

PATCH 2/3 gpu: drm: dead code elimination

this set adds support for removal of gpu drm dead code.

patch2:
num_entries is a data of unsigned type(compilers always treat as unsigned int) and SIZE_MAX == ~0,

so there is a impossible condition:
'(num_entries > ((~0) - 56) / 72) => (max(0-u32) > 256204778801521549)'.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +0 -4
index 85b0515..10a7f30 100644
@@ -71,10 +71,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
 	unsigned i;
 	int r;
 
-	if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
-				/ sizeof(struct amdgpu_bo_list_entry))
-		return -EINVAL;
-
 	size = sizeof(struct amdgpu_bo_list);
 	size += num_entries * sizeof(struct amdgpu_bo_list_entry);
 	list = kvmalloc(size, GFP_KERNEL);
Signature · 1 line
2.7.4
maintainer NAK
#1 lore raw

Am 18.12.19 um 04:50 schrieb Pan Zhang:

Quoted 7 lines

this set adds support for removal of gpu drm dead code.

patch2:
num_entries is a data of unsigned type(compilers always treat as unsigned int) and SIZE_MAX == ~0,

so there is a impossible condition:
'(num_entries > ((~0) - 56) / 72) => (max(0-u32) > 256204778801521549)'.

NAK, that calculation is not correct on 32-bit systems.

Christian.

Quoted 11 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 4 ----
  1 file changed, 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +0 -0
index 85b0515..10a7f30 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp, · line 76

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +0 -4
@@ -71,10 +71,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
  	unsigned i;
  	int r;
 
-	if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
-				/ sizeof(struct amdgpu_bo_list_entry))
-		return -EINVAL;
-
  	size = sizeof(struct amdgpu_bo_list);
  	size += num_entries * sizeof(struct amdgpu_bo_list_entry);
  	list = kvmalloc(size, GFP_KERNEL);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#2 lore raw
In reply to Pan Zhang
Quoted 7 lines · Pan Zhang

this set adds support for removal of gpu drm dead code.

patch2:
num_entries is a data of unsigned type(compilers always treat as unsigned int) and SIZE_MAX == ~0,

so there is a impossible condition:
'(num_entries > ((~0) - 56) / 72) => (max(0-u32) > 256204778801521549)'.

While this looks correct for 64-bit, where size_t is unsigned long, on 32-bit it's unsigned int, in which case this isn't dead code.

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +0 -4
index 85b0515..10a7f30 100644
@@ -71,10 +71,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
 	unsigned i;
 	int r;
 
-	if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
-				/ sizeof(struct amdgpu_bo_list_entry))
-		return -EINVAL;
-
 	size = sizeof(struct amdgpu_bo_list);
 	size += num_entries * sizeof(struct amdgpu_bo_list_entry);
 	list = kvmalloc(size, GFP_KERNEL);
Signature · 6 lines
Earthling Michel Dänzer               |               https://redhat.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#3 lore raw
Quoted 10 lines · Michel Dänzer
Quoted 8 lines

this set adds support for removal of gpu drm dead code.

patch2:
num_entries is a data of unsigned type(compilers always treat as unsigned int) and SIZE_MAX == ~0,

so there is a impossible condition:
'(num_entries > ((~0) - 56) / 72) => (max(0-u32) > 256204778801521549)'.

While this looks correct for 64-bit, where size_t is unsigned long, on 32-bit it's unsigned int, in which case this isn't dead code.

and

Quoted 3 lines · Christian König

NAK, that calculation is not correct on 32-bit systems.

Christian.

Yes, you are right. I just figured this out (because our Server usually uses 64 bits).

thanks.

Quoted 20 lines
Quoted 20 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +0 -4
index 85b0515..10a7f30 100644
@@ -71,10 +71,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev, struct drm_file *filp,
 	unsigned i;
 	int r;
 
-	if (num_entries > (SIZE_MAX - sizeof(struct amdgpu_bo_list))
-				/ sizeof(struct amdgpu_bo_list_entry))
-		return -EINVAL;
-
 	size = sizeof(struct amdgpu_bo_list);
 	size += num_entries * sizeof(struct amdgpu_bo_list_entry);
 	list = kvmalloc(size, GFP_KERNEL);