diff mbox series

[for-next,3/6] RDMA/hns: Simplify the qp state convert code

Message ID 1586760042-40516-4-git-send-email-liweihang@huawei.com (mailing list archive)
State Superseded
Delegated to: Jason Gunthorpe
Headers show
Series RDMA/hns: Codes optimization | expand

Commit Message

Weihang Li April 13, 2020, 6:40 a.m. UTC
From: Lang Cheng <chenglang@huawei.com>

Use type map table to reduce the cyclomatic complexity.

Signed-off-by: Lang Cheng <chenglang@huawei.com>
Signed-off-by: Weihang Li <liweihang@huawei.com>
---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

Comments

Jason Gunthorpe April 14, 2020, 12:56 p.m. UTC | #1
On Mon, Apr 13, 2020 at 02:40:39PM +0800, Weihang Li wrote:
> From: Lang Cheng <chenglang@huawei.com>
> 
> Use type map table to reduce the cyclomatic complexity.
> 
> Signed-off-by: Lang Cheng <chenglang@huawei.com>
> Signed-off-by: Weihang Li <liweihang@huawei.com>
>  drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 27 ++++++++++++++-------------
>  1 file changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> index 6816278..e938bd8 100644
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
> @@ -4540,19 +4540,20 @@ static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
>  	return ret;
>  }
>  
> -static inline enum ib_qp_state to_ib_qp_st(enum hns_roce_v2_qp_state state)
> -{
> -	switch (state) {
> -	case HNS_ROCE_QP_ST_RST:	return IB_QPS_RESET;
> -	case HNS_ROCE_QP_ST_INIT:	return IB_QPS_INIT;
> -	case HNS_ROCE_QP_ST_RTR:	return IB_QPS_RTR;
> -	case HNS_ROCE_QP_ST_RTS:	return IB_QPS_RTS;
> -	case HNS_ROCE_QP_ST_SQ_DRAINING:
> -	case HNS_ROCE_QP_ST_SQD:	return IB_QPS_SQD;
> -	case HNS_ROCE_QP_ST_SQER:	return IB_QPS_SQE;
> -	case HNS_ROCE_QP_ST_ERR:	return IB_QPS_ERR;
> -	default:			return -1;
> -	}
> +static int to_ib_qp_st(enum hns_roce_v2_qp_state state)
> +{
> +	const enum ib_qp_state map[] = {

Should be static

Jason
Weihang Li April 15, 2020, 1:15 a.m. UTC | #2
On 2020/4/14 20:56, Jason Gunthorpe wrote:
> On Mon, Apr 13, 2020 at 02:40:39PM +0800, Weihang Li wrote:
>> From: Lang Cheng <chenglang@huawei.com>
>>
>> Use type map table to reduce the cyclomatic complexity.
>>
>> Signed-off-by: Lang Cheng <chenglang@huawei.com>
>> Signed-off-by: Weihang Li <liweihang@huawei.com>
>>  drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 27 ++++++++++++++-------------
>>  1 file changed, 14 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
>> index 6816278..e938bd8 100644
>> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
>> @@ -4540,19 +4540,20 @@ static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
>>  	return ret;
>>  }
>>  
>> -static inline enum ib_qp_state to_ib_qp_st(enum hns_roce_v2_qp_state state)
>> -{
>> -	switch (state) {
>> -	case HNS_ROCE_QP_ST_RST:	return IB_QPS_RESET;
>> -	case HNS_ROCE_QP_ST_INIT:	return IB_QPS_INIT;
>> -	case HNS_ROCE_QP_ST_RTR:	return IB_QPS_RTR;
>> -	case HNS_ROCE_QP_ST_RTS:	return IB_QPS_RTS;
>> -	case HNS_ROCE_QP_ST_SQ_DRAINING:
>> -	case HNS_ROCE_QP_ST_SQD:	return IB_QPS_SQD;
>> -	case HNS_ROCE_QP_ST_SQER:	return IB_QPS_SQE;
>> -	case HNS_ROCE_QP_ST_ERR:	return IB_QPS_ERR;
>> -	default:			return -1;
>> -	}
>> +static int to_ib_qp_st(enum hns_roce_v2_qp_state state)
>> +{
>> +	const enum ib_qp_state map[] = {
> 
> Should be static
> 
> Jason
> 

OK, thank you.

Weihang
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
index 6816278..e938bd8 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c
@@ -4540,19 +4540,20 @@  static int hns_roce_v2_modify_qp(struct ib_qp *ibqp,
 	return ret;
 }
 
-static inline enum ib_qp_state to_ib_qp_st(enum hns_roce_v2_qp_state state)
-{
-	switch (state) {
-	case HNS_ROCE_QP_ST_RST:	return IB_QPS_RESET;
-	case HNS_ROCE_QP_ST_INIT:	return IB_QPS_INIT;
-	case HNS_ROCE_QP_ST_RTR:	return IB_QPS_RTR;
-	case HNS_ROCE_QP_ST_RTS:	return IB_QPS_RTS;
-	case HNS_ROCE_QP_ST_SQ_DRAINING:
-	case HNS_ROCE_QP_ST_SQD:	return IB_QPS_SQD;
-	case HNS_ROCE_QP_ST_SQER:	return IB_QPS_SQE;
-	case HNS_ROCE_QP_ST_ERR:	return IB_QPS_ERR;
-	default:			return -1;
-	}
+static int to_ib_qp_st(enum hns_roce_v2_qp_state state)
+{
+	const enum ib_qp_state map[] = {
+		[HNS_ROCE_QP_ST_RST] = IB_QPS_RESET,
+		[HNS_ROCE_QP_ST_INIT] = IB_QPS_INIT,
+		[HNS_ROCE_QP_ST_RTR] = IB_QPS_RTR,
+		[HNS_ROCE_QP_ST_RTS] = IB_QPS_RTS,
+		[HNS_ROCE_QP_ST_SQD] = IB_QPS_SQD,
+		[HNS_ROCE_QP_ST_SQER] = IB_QPS_SQE,
+		[HNS_ROCE_QP_ST_ERR] = IB_QPS_ERR,
+		[HNS_ROCE_QP_ST_SQ_DRAINING] = IB_QPS_SQD
+	};
+
+	return (state < ARRAY_SIZE(map)) ? map[state] : -1;
 }
 
 static int hns_roce_v2_query_qpc(struct hns_roce_dev *hr_dev,