Skip to contentSkip to conversation

amdgpu/uvd: use kmemdup

PATCH NAK Muhammad Falak R Wani 2 participants 4 messages May 19, 2016

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

PATCH 1/1 amdgpu/uvd: use kmemdup

Use kmemdup when some other buffer is immediately copied into allocated region. It replaces call to allocation followed by memcpy, by a single call to kmemdup.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +1 -3
index 01abfc2..c977ab6 100644
@@ -295,12 +295,10 @@ int amdgpu_uvd_suspend(struct amdgpu_device *adev)
 	size = amdgpu_bo_size(adev->uvd.vcpu_bo);
 	ptr = adev->uvd.cpu_addr;
 
-	adev->uvd.saved_bo = kmalloc(size, GFP_KERNEL);
+	adev->uvd.saved_bo = kmemdup(ptr, size, GFP_KERNEL);
 	if (!adev->uvd.saved_bo)
 		return -ENOMEM;
 
-	memcpy(adev->uvd.saved_bo, ptr, size);
-
 	return 0;
 }
 
Signature · 1 line
1.9.1
maintainer NAK
#1 lore raw

Am 19.05.2016 um 13:11 schrieb Muhammad Falak R Wani:

Quoted 5 lines

Use kmemdup when some other buffer is immediately copied into allocated region. It replaces call to allocation followed by memcpy, by a single call to kmemdup.

NAK, actually using memcpy() is wrong in the first place.

The UVD BO is in VRAM so the pointer is pointing to IO memory here, so this should be memcpy_fromio() instead of memcpy().

Christian.

Quoted 12 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +0 -0
index 01abfc2..c977ab6 100644
@@ -295,12 +295,10 @@ int amdgpu_uvd_suspend(struct amdgpu_device *adev)
  	size = amdgpu_bo_size(adev->uvd.vcpu_bo);
  	ptr = adev->uvd.cpu_addr;
 

drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c int amdgpu_uvd_suspend(struct amdgpu_device *adev) · line 304

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +1 -3
-	adev->uvd.saved_bo = kmalloc(size, GFP_KERNEL);
+	adev->uvd.saved_bo = kmemdup(ptr, size, GFP_KERNEL);
  	if (!adev->uvd.saved_bo)
  		return -ENOMEM;
 
-	memcpy(adev->uvd.saved_bo, ptr, size);
-
  	return 0;
  }
 

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

#2 lore raw
Quoted 5 lines · Christian König

Am 19.05.2016 um 13:11 schrieb Muhammad Falak R Wani:

Quoted 4 lines

Use kmemdup when some other buffer is immediately copied into allocated region. It replaces call to allocation followed by memcpy, by a single call to kmemdup.

Quoted 9 lines
Quoted 1 line

NAK, actually using memcpy() is wrong in the first place.

The UVD BO is in VRAM so the pointer is pointing to IO memory here, so this should be memcpy_fromio() instead of memcpy().

Christian.

Should I send V2 with the required changes, and I had a query, If memcpy was wrong, did it still work or it just got un-noticed ?

maintainer
#3 lore raw

Am 19.05.2016 um 13:49 schrieb Muhammad Falak R Wani:

Quoted 7 lines · Christian König
Quoted 6 lines

Am 19.05.2016 um 13:11 schrieb Muhammad Falak R Wani:

Quoted 5 lines

Use kmemdup when some other buffer is immediately copied into allocated region. It replaces call to allocation followed by memcpy, by a single call to kmemdup.

Quoted 8 lines
Quoted 7 lines

NAK, actually using memcpy() is wrong in the first place.

The UVD BO is in VRAM so the pointer is pointing to IO memory here, so this should be memcpy_fromio() instead of memcpy().

Christian.

Should I send V2 with the required changes, and I had a query,

I can take care of fixing this.

Quoted 1 line

If memcpy was wrong, did it still work or it just got un-noticed ?

Both, on X86 memcpy from IO memory works fine. Only on other architectures you run into problems with that.

Regards,
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel