Skip to contentSkip to conversation

RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq()

PATCH In review Jiapeng Chong 3 participants 5 messages May 7, 2021 – May 18, 2021

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

PATCH 1/1 RDMA/mlx4: Remove unnessesary check in mlx4_ib_modify_wq()

cur_state and new_state are enums and when GCC considers them as unsigned, the conditions are never met.

Clean up the following smatch warning:

drivers/infiniband/hw/mlx4/qp.c:4258 mlx4_ib_modify_wq() warn: unsigned 'cur_state' is never less than zero.

---
 drivers/infiniband/hw/mlx4/qp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/infiniband/hw/mlx4/qp.c +1 -2
index 92ddbcc..162aa59 100644
@@ -4255,8 +4255,7 @@ int mlx4_ib_modify_wq(struct ib_wq *ibwq, struct ib_wq_attr *wq_attr,
 						     ibwq->state;
 	new_state = wq_attr_mask & IB_WQ_STATE ? wq_attr->wq_state : cur_state;
 
-	if (cur_state  < IB_WQS_RESET || cur_state  > IB_WQS_ERR ||
-	    new_state < IB_WQS_RESET || new_state > IB_WQS_ERR)
+	if (cur_state > IB_WQS_ERR || new_state > IB_WQS_ERR)
 		return -EINVAL;
 
 	if ((new_state == IB_WQS_RDY) && (cur_state == IB_WQS_ERR))
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jiapeng Chong

cur_state and new_state are enums and when GCC considers them as unsigned, the conditions are never met.

Clean up the following smatch warning:

Quoted 8 lines

drivers/infiniband/hw/mlx4/qp.c:4258 mlx4_ib_modify_wq() warn: unsigned 'cur_state' is never less than zero.

---
 drivers/infiniband/hw/mlx4/qp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Thanks,

#2 lore raw
In reply to Jiapeng Chong
Quoted 19 lines · Jiapeng Chong

cur_state and new_state are enums and when GCC considers them as unsigned, the conditions are never met.

Clean up the following smatch warning:

drivers/infiniband/hw/mlx4/qp.c:4258 mlx4_ib_modify_wq() warn: unsigned 'cur_state' is never less than zero.

---
 drivers/infiniband/hw/mlx4/qp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/infiniband/hw/mlx4/qp.c +0 -0
index 92ddbcc..162aa59 100644

drivers/infiniband/hw/mlx4/qp.c int mlx4_ib_modify_wq(struct ib_wq *ibwq, struct ib_wq_attr *wq_attr, · line 4259

Quoted 7 lines
drivers/infiniband/hw/mlx4/qp.c +1 -2
@@ -4255,8 +4255,7 @@ int mlx4_ib_modify_wq(struct ib_wq *ibwq, struct ib_wq_attr *wq_attr,
 						     ibwq->state;
 	new_state = wq_attr_mask & IB_WQ_STATE ? wq_attr->wq_state : cur_state;
 
-	if (cur_state  < IB_WQS_RESET || cur_state  > IB_WQS_ERR ||
-	    new_state < IB_WQS_RESET || new_state > IB_WQS_ERR)
+	if (cur_state > IB_WQS_ERR || new_state > IB_WQS_ERR)
 		return -EINVAL;

Actually the more robust change will be to move this change to the ib_uverbs_ex_modify_wq().

Thanks

Quoted 5 lines
drivers/infiniband/hw/mlx4/qp.c +0 -0
 	if ((new_state == IB_WQS_RDY) && (cur_state == IB_WQS_ERR))
Signature · 1 line
1.8.3.1
maintainer
#3 lore raw
In reply to Jiapeng Chong
Quoted 2 lines · Jiapeng Chong

cur_state and new_state are enums and when GCC considers them as unsigned, the conditions are never met.

But doesn't gcc consider enums to be 'int' as the standard requires?

This change looks really sketchy to me, cur_state and new_state are both userspace controlled data. We should not make assumptions about the underlying signedness of an enum when validating user data.

Jason

#4 lore raw
Quoted 5 lines · Jason Gunthorpe
Quoted 2 lines · Jiapeng Chong

cur_state and new_state are enums and when GCC considers them as unsigned, the conditions are never met.

But doesn't gcc consider enums to be 'int' as the standard requires?

Ohh, I missed that.

Quoted 4 lines

This change looks really sketchy to me, cur_state and new_state are both userspace controlled data. We should not make assumptions about the underlying signedness of an enum when validating user data.

I still think that the right change should be in ib_uverbs_ex_modify_wq(), so both mlx4 and mlx5 will be protected.

Thanks

Quoted 2 lines

Jason