Skip to contentSkip to conversation

drm/amdkfd: remove dead code in kq_initialize

PATCH In review Jesse Zhang 2 participants 3 messages Jun 3, 2024 – Jun 5, 2024

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

PATCH 10/12 drm/amdkfd: remove dead code in kq_initialize

The queue type can only be KFD_QUEUE_TYPE_DIQ or KFD_QUEUE_TYPE_HIQ, and the default cannot be reached.

---
 drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -3
index 32c926986dbb..3142b2593e2b 100644
@@ -67,9 +67,6 @@ static bool kq_initialize(struct kernel_queue *kq, struct kfd_node *dev,
 	case KFD_QUEUE_TYPE_HIQ:
 		kq->mqd_mgr = dev->dqm->mqd_mgrs[KFD_MQD_TYPE_HIQ];
 		break;
-	default:
-		pr_err("Invalid queue type %d\n", type);
-		return false;
 	}
 
 	if (!kq->mqd_mgr)
Signature · 1 line
2.25.1
maintainer Acked-by on v1 10/12
#1 lore raw
Quoted 2 lines · Jesse Zhang

The queue type can only be KFD_QUEUE_TYPE_DIQ or KFD_QUEUE_TYPE_HIQ, and the default cannot be reached.

I wonder, if you remove the default case, I guess you are relying on the compiler or a static checker to ensure that we can only pass valid enum values to this function. I don't think C compilers are that strict. You could pass a random integer to the function. That said, this function only has two callers, and both of them use a proper enum value.

Quoted 2 lines
Quoted 18 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 3 ---
  1 file changed, 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -3
index 32c926986dbb..3142b2593e2b 100644
@@ -67,9 +67,6 @@ static bool kq_initialize(struct kernel_queue *kq, struct kfd_node *dev,
  	case KFD_QUEUE_TYPE_HIQ:
  		kq->mqd_mgr = dev->dqm->mqd_mgrs[KFD_MQD_TYPE_HIQ];
  		break;
-	default:
-		pr_err("Invalid queue type %d\n", type);
-		return false;
  	}
 
  	if (!kq->mqd_mgr)
author Acked-by Felix Kuehling
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

HI Felix

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Wednesday, June 5, 2024 2:45 AM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Huang, Tim <[email protected]>
Subject: Re: [PATCH 10/12] drm/amdkfd: remove dead code in kq_initialize

Quoted 2 lines · Jesse Zhang

The queue type can only be KFD_QUEUE_TYPE_DIQ or KFD_QUEUE_TYPE_HIQ, and the default cannot be reached.

I wonder, if you remove the default case, I guess you are relying on the compiler or a static checker to ensure that we can only pass valid enum values to this function. I don't think C compilers are that strict. You could pass a random integer to the function. That said, this function only has two callers, and both of them use a proper enum value.

[Zhang, Jesse(Jie)] At the beginning of the function kq_initialize, we check the queue type that can ensure the warning about C compilers.

static bool kq_initialize(struct kernel_queue *kq, struct kfd_node *dev,
enum kfd_queue_type type, unsigned int queue_size)

{
        struct queue_properties prop;
        int retval;
        union PM4_MES_TYPE_3_HEADER nop;

        if (WARN_ON(type != KFD_QUEUE_TYPE_DIQ && type != KFD_QUEUE_TYPE_HIQ))
                return false;
             ...
}

Thanks
Jesse

Quoted 2 lines
Quoted 19 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c | 3 ---
  1 file changed, 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c +0 -3
index 32c926986dbb..3142b2593e2b 100644
@@ -67,9 +67,6 @@ static bool kq_initialize(struct kernel_queue *kq, struct kfd_node *dev,
      case KFD_QUEUE_TYPE_HIQ:
              kq->mqd_mgr = dev->dqm->mqd_mgrs[KFD_MQD_TYPE_HIQ];
              break;
-     default:
-             pr_err("Invalid queue type %d\n", type);
-             return false;
      }
 
      if (!kq->mqd_mgr)