Skip to contentSkip to conversation

amdkfd: Check kvmalloc return before memcpy

PATCH In review Kent Russell 3 participants 3 messages Nov 2, 2020

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

PATCH 1/1 amdkfd: Check kvmalloc return before memcpy

If we can't kvmalloc the pcrat_image, then we shouldn't memcpy

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -1
index cdd5032d5c0e..a0acf2310357 100644
@@ -804,10 +804,10 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
 	}
 
 	pcrat_image = kvmalloc(crat_table->length, GFP_KERNEL);
-	memcpy(pcrat_image, crat_table, crat_table->length);
 	if (!pcrat_image)
 		return -ENOMEM;
 
+	memcpy(pcrat_image, crat_table, crat_table->length);
 	*crat_image = pcrat_image;
 	*size = crat_table->length;
 
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only - Internal Distribution Only]

________________________________
From: amd-gfx <[email protected]> on behalf of Kent Russell <[email protected]>
Sent: Monday, November 2, 2020 11:27 AM
To: [email protected] <[email protected]>
Cc: Russell, Kent <[email protected]>
Subject: [PATCH] amdkfd: Check kvmalloc return before memcpy

If we can't kvmalloc the pcrat_image, then we shouldn't memcpy

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -1
index cdd5032d5c0e..a0acf2310357 100644
@@ -804,10 +804,10 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
         }
 
         pcrat_image = kvmalloc(crat_table->length, GFP_KERNEL);
-       memcpy(pcrat_image, crat_table, crat_table->length);
         if (!pcrat_image)
                 return -ENOMEM;
 
+       memcpy(pcrat_image, crat_table, crat_table->length);
         *crat_image = pcrat_image;
         *size = crat_table->length;
 

--
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Calexander.deucher%40amd.com%7C20c8797c2a6d4fb8bf5a08d87f4c3732%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637399312636837144%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=84VCnd9ugeRKlAyqOYpXHm2PvPXUhM0gQjJd9AR95mA%3D&amp;reserved=0

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

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Kent Russell

Am 2020-11-02 um 11:27 a.m. schrieb Kent Russell:

Quoted 4 lines

If we can't kvmalloc the pcrat_image, then we shouldn't memcpy

Quoted 10 lines
---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +0 -0
index cdd5032d5c0e..a0acf2310357 100644
@@ -804,10 +804,10 @@ int kfd_create_crat_image_acpi(void **crat_image, size_t *size)
 	}

drivers/gpu/drm/amd/amdkfd/kfd_crat.c int kfd_create_crat_image_acpi(void **crat_image, size_t *size) · line 813

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -1
 
 	pcrat_image = kvmalloc(crat_table->length, GFP_KERNEL);
-	memcpy(pcrat_image, crat_table, crat_table->length);
 	if (!pcrat_image)
 		return -ENOMEM;
 
+	memcpy(pcrat_image, crat_table, crat_table->length);
 	*crat_image = pcrat_image;
 	*size = crat_table->length;
 

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