[dpdk-dev] net/mlx4: fix shifts of signed values
Checks
Commit Message
This patch addresses the following issues reported by cppcheck:
[drivers/net/mlx4/mlx4_rxtx.c:266]: (error) Shifting signed 32-bit value
by 31 bits is undefined behaviour
[drivers/net/mlx4/mlx4_rxtx.c:624]: (error) Shifting signed 32-bit value
by 31 bits is undefined behaviour
[drivers/net/mlx4/mlx4_txq.c:89]: (error) Shifting signed 32-bit value by
31 bits is undefined behaviour
[drivers/net/mlx4/mlx4_txq.c:91]: (error) Shifting signed 32-bit value by
31 bits is undefined behaviour
Fixes: 78e81a9844f8 ("net/mlx4: merge Tx queue rings management")
Cc: stable@dpdk.org
Cc: Matan Azrad <matan@mellanox.com>
Reported-by: Ferruh Yigit <ferruh.yigit@intel.com>
Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
drivers/net/mlx4/mlx4_rxtx.c | 4 ++--
drivers/net/mlx4/mlx4_txq.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
Comments
Wednesday, May 16, 2018 7:21 PM, Adrien Mazarguil:
> Subject: [PATCH] net/mlx4: fix shifts of signed values
>
> This patch addresses the following issues reported by cppcheck:
>
> [drivers/net/mlx4/mlx4_rxtx.c:266]: (error) Shifting signed 32-bit value
> by 31 bits is undefined behaviour
> [drivers/net/mlx4/mlx4_rxtx.c:624]: (error) Shifting signed 32-bit value
> by 31 bits is undefined behaviour
> [drivers/net/mlx4/mlx4_txq.c:89]: (error) Shifting signed 32-bit value by
> 31 bits is undefined behaviour
> [drivers/net/mlx4/mlx4_txq.c:91]: (error) Shifting signed 32-bit value by
> 31 bits is undefined behaviour
>
> Fixes: 78e81a9844f8 ("net/mlx4: merge Tx queue rings management")
> Cc: stable@dpdk.org
> Cc: Matan Azrad <matan@mellanox.com>
>
> Reported-by: Ferruh Yigit <ferruh.yigit@intel.com>
> Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Applied to next-net-mlx, thanks.
@@ -263,7 +263,7 @@ mlx4_txq_stamp_freed_wqe(struct mlx4_sq *sq, volatile uint32_t *start,
} while (start != (volatile uint32_t *)sq->eob);
start = (volatile uint32_t *)sq->buf;
/* Flip invalid stamping ownership. */
- stamp ^= RTE_BE32(0x1 << MLX4_SQ_OWNER_BIT);
+ stamp ^= RTE_BE32(1u << MLX4_SQ_OWNER_BIT);
sq->stamp = stamp;
if (start == end)
return size;
@@ -621,7 +621,7 @@ mlx4_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
ctrl_next = (volatile struct mlx4_wqe_ctrl_seg *)
((volatile uint8_t *)ctrl_next - sq->size);
/* Flip HW valid ownership. */
- sq->owner_opcode ^= 0x1 << MLX4_SQ_OWNER_BIT;
+ sq->owner_opcode ^= 1u << MLX4_SQ_OWNER_BIT;
}
/*
* For raw Ethernet, the SOLICIT flag is used to indicate
@@ -86,9 +86,9 @@ mlx4_txq_fill_dv_obj_info(struct txq *txq, struct mlx4dv_obj *mlxdv)
uint32_t headroom_size = 2048 + (1 << dqp->sq.wqe_shift);
/* Continuous headroom size bytes must always stay freed. */
sq->remain_size = sq->size - headroom_size;
- sq->owner_opcode = MLX4_OPCODE_SEND | (0 << MLX4_SQ_OWNER_BIT);
+ sq->owner_opcode = MLX4_OPCODE_SEND | (0u << MLX4_SQ_OWNER_BIT);
sq->stamp = rte_cpu_to_be_32(MLX4_SQ_STAMP_VAL |
- (0 << MLX4_SQ_OWNER_BIT));
+ (0u << MLX4_SQ_OWNER_BIT));
sq->db = dqp->sdb;
sq->doorbell_qpn = dqp->doorbell_qpn;
cq->buf = dcq->buf.buf;