The 'size' argument in kfd_create_crat_image_virtual() is not used
by callers to retrieve the allocated CRAT image size. The callers
rely solely on the returned image pointer and inspect the parsed CRAT
table header directly for entry counts and lengths.

Additionally, in kfd_topology_init(), the 'kdev' pointer assignment
via list_first_entry() after parsing the CPU CRAT table is not being
used and can be removed.

Clean up the function signature of kfd_create_crat_image_virtual() by
dropping the unused 'size' parameter, manage the buffer size locally,
and remove the unused variable assignments in kfd_topology_init().

Co-developed-by: Donet Tom <[email protected]>
Signed-off-by: Donet Tom <[email protected]>
Signed-off-by: Dhruv B <[email protected]>
---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c     | 10 ++++------
 drivers/gpu/drm/amd/amdkfd/kfd_crat.h     |  2 +-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 11 ++---------
 3 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
index 6e0df685503d..99b0c7f825fe 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
@@ -2411,7 +2411,6 @@ static int kfd_create_vcrat_image_gpu(void *pcrat_image,
  *
  *     @crat_image: VCRAT image created because ACPI does not have a
  *                  CRAT for this device
- *     @size: [OUT] size of virtual crat_image
  *     @flags: COMPUTE_UNIT_CPU - Create VCRAT for CPU device
  *             COMPUTE_UNIT_GPU - Create VCRAT for GPU
  *             (COMPUTE_UNIT_CPU | COMPUTE_UNIT_GPU) - Create VCRAT for APU
@@ -2421,7 +2420,7 @@ static int kfd_create_vcrat_image_gpu(void *pcrat_image,
  *
  *     Return 0 if successful else return -ve value
  */
-int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
+int kfd_create_crat_image_virtual(void **crat_image,
                                  int flags, struct kfd_node *kdev,
                                  uint32_t proximity_domain)
 {
@@ -2449,9 +2448,8 @@ int kfd_create_crat_image_virtual(void **crat_image, 
size_t *size,
                pcrat_image = kvmalloc(dyn_size, GFP_KERNEL);
                if (!pcrat_image)
                        return -ENOMEM;
-               *size = dyn_size;
                pr_debug("CRAT size is %ld", dyn_size);
-               ret = kfd_create_vcrat_image_cpu(pcrat_image, size);
+               ret = kfd_create_vcrat_image_cpu(pcrat_image, &dyn_size);
                break;
        case COMPUTE_UNIT_GPU:
                if (!kdev)
@@ -2459,8 +2457,8 @@ int kfd_create_crat_image_virtual(void **crat_image, 
size_t *size,
                pcrat_image = kvmalloc(VCRAT_SIZE_FOR_GPU, GFP_KERNEL);
                if (!pcrat_image)
                        return -ENOMEM;
-               *size = VCRAT_SIZE_FOR_GPU;
-               ret = kfd_create_vcrat_image_gpu(pcrat_image, size, kdev,
+               dyn_size = VCRAT_SIZE_FOR_GPU;
+               ret = kfd_create_vcrat_image_gpu(pcrat_image, &dyn_size, kdev,
                                                 proximity_domain);
                break;
        case (COMPUTE_UNIT_CPU | COMPUTE_UNIT_GPU):
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.h 
b/drivers/gpu/drm/amd/amdkfd/kfd_crat.h
index a8ca7ecb6d27..418a3939eda3 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_crat.h
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_crat.h
@@ -313,7 +313,7 @@ int kfd_get_gpu_cache_info(struct kfd_node *kdev, struct 
kfd_gpu_cache_info **pc
 void kfd_destroy_crat_image(void *crat_image);
 int kfd_parse_crat_table(void *crat_image, struct list_head *device_list,
                         uint32_t proximity_domain);
-int kfd_create_crat_image_virtual(void **crat_image, size_t *size,
+int kfd_create_crat_image_virtual(void **crat_image,
                                  int flags, struct kfd_node *kdev,
                                  uint32_t proximity_domain);
 
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c 
b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
index 35b3abe57b80..b38d12f3da84 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_topology.c
@@ -996,7 +996,6 @@ static void kfd_add_non_crat_information(struct 
kfd_topology_device *kdev)
 int kfd_topology_init(void)
 {
        void *crat_image = NULL;
-       size_t image_size = 0;
        int ret;
        struct list_head temp_topology_device_list;
        int cpu_only_node = 0;
@@ -1023,8 +1022,7 @@ int kfd_topology_init(void)
         */
        proximity_domain = 0;
 
-       ret = kfd_create_crat_image_virtual(&crat_image, &image_size,
-                                           COMPUTE_UNIT_CPU, NULL,
+       ret = kfd_create_crat_image_virtual(&crat_image, COMPUTE_UNIT_CPU, NULL,
                                            proximity_domain);
        cpu_only_node = 1;
        if (ret) {
@@ -1040,9 +1038,6 @@ int kfd_topology_init(void)
                goto err;
        }
 
-       kdev = list_first_entry(&temp_topology_device_list,
-                               struct kfd_topology_device, list);
-
        down_write(&topology_lock);
        kfd_topology_update_device_list(&temp_topology_device_list,
                                        &topology_device_list);
@@ -1871,11 +1866,9 @@ static int kfd_topology_add_device_locked(struct 
kfd_node *gpu,
        int proximity_domain = ++topology_crat_proximity_domain;
        struct list_head temp_topology_device_list;
        void *crat_image = NULL;
-       size_t image_size = 0;
        int res;
 
-       res = kfd_create_crat_image_virtual(&crat_image, &image_size,
-                                           COMPUTE_UNIT_GPU, gpu,
+       res = kfd_create_crat_image_virtual(&crat_image, COMPUTE_UNIT_GPU, gpu,
                                            proximity_domain);
        if (res) {
                dev_err(gpu->adev->dev, "Error creating VCRAT\n");
-- 
2.54.0 (Apple Git-157)

Reply via email to