Skip to contentSkip to conversation

net/mlx5/hws: fix possible negative return on sq create

PATCH In review Alex Vesker 2 participants 5 messages Nov 3, 2022 – Nov 8, 2022 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/mlx5/hws: fix possible negative return on sq create

The sysconf call can return a negative value (-1) on failure this will lead to posix_memalign to fail. This is not a realistic case which was found by the static checkers.

Fixes 3eb7488 ("net/mlx5/hws: add send layer")
---
 drivers/net/mlx5/hws/mlx5dr_send.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/mlx5/hws/mlx5dr_send.c +4 -2
index 26904a9040..1e9953a38f 100644
@@ -524,6 +524,7 @@ static int mlx5dr_send_ring_open_sq(struct mlx5dr_context *ctx,
 	size_t sq_log_buf_sz;
 	size_t buf_aligned;
 	size_t sq_buf_sz;
+	size_t page_size;
 	size_t buf_sz;
 	int err;
 
@@ -532,8 +533,9 @@ static int mlx5dr_send_ring_open_sq(struct mlx5dr_context *ctx,
 	sq_buf_sz = 1 << (sq_log_buf_sz + log2above(MLX5_SEND_WQE_BB));
 	sq->reg_addr = queue->uar->reg_addr;
 
-	buf_aligned = align(sq_buf_sz, sysconf(_SC_PAGESIZE));
-	err = posix_memalign((void **)&sq->buf, sysconf(_SC_PAGESIZE), buf_aligned);
+	page_size = sysconf(_SC_PAGESIZE);
+	buf_aligned = align(sq_buf_sz, page_size);
+	err = posix_memalign((void **)&sq->buf, page_size, buf_aligned);
 	if (err) {
 		rte_errno = ENOMEM;
 		return err;
Signature · 1 line
2.18.1
#1 lore raw

Also forgot to add to commit message:
Coverity issue: 381674

Quoted 52 lines

-----Original Message-----
From: Alex Vesker <[email protected]>
Sent: Thursday, November 3, 2022 2:52 PM
To: Alex Vesker <[email protected]>; Slava Ovsiienko <[email protected]>; NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Ori Kam <[email protected]>
Subject: [PATCH] net/mlx5/hws: fix possible negative return on sq create

The sysconf call can return a negative value (-1) on failure this will lead to posix_memalign to fail. This is not a realistic case which was found by the static checkers.

Fixes 3eb7488 ("net/mlx5/hws: add send layer")
---
 drivers/net/mlx5/hws/mlx5dr_send.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/mlx5/hws/mlx5dr_send.c +4 -2
index 26904a9040..1e9953a38f 100644
@@ -524,6 +524,7 @@ static int mlx5dr_send_ring_open_sq(struct
 mlx5dr_context *ctx,
 	size_t sq_log_buf_sz;
 	size_t buf_aligned;
 	size_t sq_buf_sz;
+	size_t page_size;
 	size_t buf_sz;
 	int err;
@@ -532,8 +533,9 @@ static int mlx5dr_send_ring_open_sq(struct
 mlx5dr_context *ctx,
 	sq_buf_sz = 1 << (sq_log_buf_sz +
 log2above(MLX5_SEND_WQE_BB));
 	sq->reg_addr = queue->uar->reg_addr;
 
-	buf_aligned = align(sq_buf_sz, sysconf(_SC_PAGESIZE));
-	err = posix_memalign((void **)&sq->buf, sysconf(_SC_PAGESIZE),
 buf_aligned);
+	page_size = sysconf(_SC_PAGESIZE);
+	buf_aligned = align(sq_buf_sz, page_size);
+	err = posix_memalign((void **)&sq->buf, page_size, buf_aligned);
drivers/net/mlx5/hws/mlx5dr_send.c +0 -1
 	if (err) {
 		rte_errno = ENOMEM;
 		return err;
--

2.18.1

#2 lore raw

PATCH 4/4 net/mlx5/hws: fix possible negative return on sq create

In reply to Alex Vesker

The sysconf call can return a negative value (-1) on failure this will lead to posix_memalign to fail. This is not a realistic case which was found by the static checkers.

Coverity issue: 381674

Fixes 3eb7488 ("net/mlx5/hws: add send layer")
---
 drivers/net/mlx5/hws/mlx5dr_send.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/mlx5/hws/mlx5dr_send.c +4 -2
index 26904a9040..1e9953a38f 100644
@@ -524,6 +524,7 @@ static int mlx5dr_send_ring_open_sq(struct mlx5dr_context *ctx,
 	size_t sq_log_buf_sz;
 	size_t buf_aligned;
 	size_t sq_buf_sz;
+	size_t page_size;
 	size_t buf_sz;
 	int err;
 
@@ -532,8 +533,9 @@ static int mlx5dr_send_ring_open_sq(struct mlx5dr_context *ctx,
 	sq_buf_sz = 1 << (sq_log_buf_sz + log2above(MLX5_SEND_WQE_BB));
 	sq->reg_addr = queue->uar->reg_addr;
 
-	buf_aligned = align(sq_buf_sz, sysconf(_SC_PAGESIZE));
-	err = posix_memalign((void **)&sq->buf, sysconf(_SC_PAGESIZE), buf_aligned);
+	page_size = sysconf(_SC_PAGESIZE);
+	buf_aligned = align(sq_buf_sz, page_size);
+	err = posix_memalign((void **)&sq->buf, page_size, buf_aligned);
 	if (err) {
 		rte_errno = ENOMEM;
 		return err;
Signature · 1 line
2.18.1
#3 lore raw

PATCH 1/1 net/mlx5/hws: fix possible negative return on sq create

In reply to Alex Vesker

The sysconf call can return a negative value (-1) on failure this will lead to posix_memalign to fail. This is not a realistic case which was found by the static checkers.

Coverity issue: 381674

Fixes 3eb7488 ("net/mlx5/hws: add send layer")
---
 drivers/net/mlx5/hws/mlx5dr_send.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/mlx5/hws/mlx5dr_send.c +4 -2
index 26904a9040..1e9953a38f 100644
@@ -524,6 +524,7 @@ static int mlx5dr_send_ring_open_sq(struct mlx5dr_context *ctx,
 	size_t sq_log_buf_sz;
 	size_t buf_aligned;
 	size_t sq_buf_sz;
+	size_t page_size;
 	size_t buf_sz;
 	int err;
 
@@ -532,8 +533,9 @@ static int mlx5dr_send_ring_open_sq(struct mlx5dr_context *ctx,
 	sq_buf_sz = 1 << (sq_log_buf_sz + log2above(MLX5_SEND_WQE_BB));
 	sq->reg_addr = queue->uar->reg_addr;
 
-	buf_aligned = align(sq_buf_sz, sysconf(_SC_PAGESIZE));
-	err = posix_memalign((void **)&sq->buf, sysconf(_SC_PAGESIZE), buf_aligned);
+	page_size = sysconf(_SC_PAGESIZE);
+	buf_aligned = align(sq_buf_sz, page_size);
+	err = posix_memalign((void **)&sq->buf, page_size, buf_aligned);
 	if (err) {
 		rte_errno = ENOMEM;
 		return err;
Signature · 1 line
2.18.1
#4 lore raw
In reply to Alex Vesker

Hi,

Quoted 10 lines

-----Original Message-----
From: Alex Vesker <[email protected]>
Sent: Thursday, November 3, 2022 2:52 PM
To: Alex Vesker <[email protected]>; Slava Ovsiienko <[email protected]>; NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; Suanming Mou <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Ori Kam <[email protected]>
Subject: [PATCH] net/mlx5/hws: fix possible negative return on sq create

Quoted 5 lines

The sysconf call can return a negative value (-1) on failure this will lead to posix_memalign to fail. This is not a realistic case which was found by the static checkers.

Fixes 3eb7488 ("net/mlx5/hws: add send layer")

missing empty line between fixes and signed-off-by will handle during integration.

Quoted 2 lines

Patch applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh