Skip to contentSkip to conversation

drivers: fix vmxnet3 return wrong error code in initializing

PATCH Superseded root 3 participants 9 messages May 30, 2023 – Jun 9, 2023

Subsystems (2)
lore
Share & tools
lore

root

author
#0 lore raw

PATCH 1/1 drivers: fix vmxnet3 return wrong error code in initializing

From: Kaijun Zeng <[email protected]>

In vmxnet3_dev_rxtx_init(), a wrong error code may be thrown after it invokes vmxnet3_post_rx_bufs() because it negates the error code before returning it. It causes rte_eth_dev_start() to give a positive number to the invoker, but it should be a negative number, as described in the comments.

Bugzilla ID: 1239

---
 drivers/net/vmxnet3/vmxnet3_rxtx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/vmxnet3/vmxnet3_rxtx.c +1 -1
index a875ffec07..73ec1e4727 100644
@@ -1315,7 +1315,7 @@ vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev)
 				PMD_INIT_LOG(ERR,
 					     "ERROR: Posting Rxq: %d buffers ring: %d",
 					     i, j);
-				return -ret;
+				return ret;
 			}
 			/*
 			 * Updating device with the index:next2fill to fill the
Signature · 1 line
2.30.2
#1 lore raw
Quoted 19 lines · root

From: Kaijun Zeng <[email protected]>

In vmxnet3_dev_rxtx_init(), a wrong error code may be thrown after it invokes vmxnet3_post_rx_bufs() because it negates the error code before returning it. It causes rte_eth_dev_start() to give a positive number to the invoker, but it should be a negative number, as described in the comments.

Bugzilla ID: 1239

---
 drivers/net/vmxnet3/vmxnet3_rxtx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/vmxnet3/vmxnet3_rxtx.c +0 -0
index a875ffec07..73ec1e4727 100644

drivers/net/vmxnet3/vmxnet3_rxtx.c vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev) · line 1318

Quoted 5 lines
drivers/net/vmxnet3/vmxnet3_rxtx.c +1 -1
@@ -1315,7 +1315,7 @@ vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev)
 				PMD_INIT_LOG(ERR,
 					     "ERROR: Posting Rxq: %d buffers ring: %d",
 					     i, j);
-				return -ret;
+				return ret;

Hi Kaijun,

Thanks for the fix, it looks valid.

But 'ret' being 0 also seems problematic, mentioned code is as following:

```
ret = vmxnet3_post_rx_bufs(rxq, j);
if (ret <= 0) {
	PMD_INIT_LOG(ERR,
		"ERROR: Posting Rxq: %d buffers ring: %d", i, j);
	return ret;
}
```

'vmxnet3_dev_rxtx_init()' can return 0 and failure, but caller will take it as success.

Perhaps better to send an explicit error:

```
if (ret <= 0) {
	...
	return -EXXX
}
```

btw, for the next version of the patch, please use 'net/vmxnet3: ' prefix for patch title, like:
"net/vmxnet3: fix return code in initializing"

Also please include following Fixes tag in the commit log:

```
Fixes: dfaff37fc46d ("vmxnet3: import new vmxnet3 poll mode driver
implementation")
Cc: [email protected]
```

For more details you can check contribution guide:
https://doc.dpdk.org/guides/contributing/patches.html#commit-messages-subject-line

#2 lore raw

PATCH v2 1/1 net/vmxnet3: fix return code in initializing

In reply to root

Improve error handling

Fixes dfaff37fc46d ("vmxnet3: import new vmxnet3 poll mode driver implementation")
---
 drivers/net/vmxnet3/vmxnet3_rxtx.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/net/vmxnet3/vmxnet3_rxtx.c +11 -1
index 73ec1e4727..e615d40d09 100644
@@ -1311,7 +1311,17 @@ vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev)
 		for (j = 0; j < VMXNET3_RX_CMDRING_SIZE; j++) {
 			/* Passing 0 as alloc_num will allocate full ring */
 			ret = vmxnet3_post_rx_bufs(rxq, j);
-			if (ret <= 0) {
+
+			/* Zero number of descriptors in the configuration of the RX queue */
+			if (ret == 0) {
+				PMD_INIT_LOG(ERR,
+					"ERROR: Zero descriptor requirement in Rx queue: %d,"
+					"buffers ring: %d\n",
+					i, j);
+				return -EINVAL;
+			}
+			/* Return the errno */
+			if (ret < 0) {
 				PMD_INIT_LOG(ERR,
 					     "ERROR: Posting Rxq: %d buffers ring: %d",
 					     i, j);
Signature · 1 line
2.30.2
#3 lore raw

Re: [PATCH v2] net/vmxnet3: fix return code in initializing

Quoted 23 lines · Kaijun Zeng

Improve error handling

Fixes dfaff37fc46d ("vmxnet3: import new vmxnet3 poll mode driver implementation")
---
 drivers/net/vmxnet3/vmxnet3_rxtx.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/net/vmxnet3/vmxnet3_rxtx.c +4 -1
index 73ec1e4727..e615d40d09 100644
@@ -1311,7 +1311,17 @@ vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev)
 		for (j = 0; j < VMXNET3_RX_CMDRING_SIZE; j++) {
 			/* Passing 0 as alloc_num will allocate full ring */
 			ret = vmxnet3_post_rx_bufs(rxq, j);
-			if (ret <= 0) {
+
+			/* Zero number of descriptors in the configuration of the RX queue */
+			if (ret == 0) {
+				PMD_INIT_LOG(ERR,

drivers/net/vmxnet3/vmxnet3_rxtx.c vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev) · line 1327

Quoted 10 lines
drivers/net/vmxnet3/vmxnet3_rxtx.c +7 -0
+					"ERROR: Zero descriptor requirement in Rx queue: %d,"
+					"buffers ring: %d\n",
+					i, j);
+				return -EINVAL;
+			}
+			/* Return the errno */
+			if (ret < 0) {
 				PMD_INIT_LOG(ERR,
 					     "ERROR: Posting Rxq: %d buffers ring: %d",
 					     i, j);

Looks good to me, @Jochen any objection?

#4 lore raw

Re: [PATCH v2] net/vmxnet3: fix return code in initializing

In reply to Kaijun Zeng

drivers/net/vmxnet3/vmxnet3_rxtx.c vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev) · line 1320

Quoted 4 lines · On Fri, 2 Jun 2023 12:44:38 -0400 Kaijun Zeng <[email protected]> wrote:
drivers/net/vmxnet3/vmxnet3_rxtx.c +4 -0
+				PMD_INIT_LOG(ERR,
+					"ERROR: Zero descriptor requirement in Rx queue: %d,"
+					"buffers ring: %d\n",
+					i, j);

Please don't split messages across source lines, it makes harder for developers to use tools to scan source for message.

Often, when message is long, it means that there is redundant information or poor wording. For example, in your message "ERROR:" is redundant.

#5 lore raw

Re: [PATCH v2] net/vmxnet3: fix return code in initializing

Quoted 11 lines · Stephen Hemminger

drivers/net/vmxnet3/vmxnet3_rxtx.c vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev) · line 1320

Quoted 4 lines · On Fri, 2 Jun 2023 12:44:38 -0400 Kaijun Zeng <[email protected]> wrote:
drivers/net/vmxnet3/vmxnet3_rxtx.c +4 -0
+				PMD_INIT_LOG(ERR,
+					"ERROR: Zero descriptor requirement in Rx queue: %d,"
+					"buffers ring: %d\n",
+					i, j);

Please don't split messages across source lines, it makes harder for developers to use tools to scan source for message.

Quoted 3 lines

Often, when message is long, it means that there is redundant information or poor wording. For example, in your message "ERROR:" is redundant.

Agree that 'ERROR:' is redundant, and +1 to not split log message.

Kaijun,

Would you mind sending a new version with above changes?

Thanks,
ferruh

#6 lore raw

PATCH v3 1/1 net/vmxnet3: fix return code in initializing

In reply to Kaijun Zeng

Improve error handling

Bugzilla ID: 1239

Fixes dfaff37fc46d ("vmxnet3: import new vmxnet3 poll mode driver implementation")

---
v3:
* Improve coding style

v2:
* Improve error handling

---
 drivers/net/vmxnet3/vmxnet3_rxtx.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_rxtx.c +11 -4
index a875ffec07..e6e36dca93 100644
@@ -1311,11 +1311,18 @@ vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev)
 		for (j = 0; j < VMXNET3_RX_CMDRING_SIZE; j++) {
 			/* Passing 0 as alloc_num will allocate full ring */
 			ret = vmxnet3_post_rx_bufs(rxq, j);
-			if (ret <= 0) {
+
+			/* Zero number of descriptors in the configuration of the RX queue */
+			if (ret == 0) {
 				PMD_INIT_LOG(ERR,
-					     "ERROR: Posting Rxq: %d buffers ring: %d",
-					     i, j);
-				return -ret;
+					"Invalid configuration in Rx queue: %d, buffers ring: %d\n",
+					i, j);
+				return -EINVAL;
+			}
+			/* Return the error number */
+			if (ret < 0) {
+				PMD_INIT_LOG(ERR, "Posting Rxq: %d buffers ring: %d", i, j);
+				return ret;
 			}
 			/*
 			 * Updating device with the index:next2fill to fill the
Signature · 1 line
2.30.2
#8 lore raw

PATCH 1/1 net/vmxnet3: fix return code in initializing

In reply to root

Improve error handling and code style

Bugzilla ID: 1239

Fixes dfaff37fc46d ("vmxnet3: import new vmxnet3 poll mode driver implementation")
---
 drivers/net/vmxnet3/vmxnet3_rxtx.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/net/vmxnet3/vmxnet3_rxtx.c +11 -4
index a875ffec07..e6e36dca93 100644
@@ -1311,11 +1311,18 @@ vmxnet3_dev_rxtx_init(struct rte_eth_dev *dev)
 		for (j = 0; j < VMXNET3_RX_CMDRING_SIZE; j++) {
 			/* Passing 0 as alloc_num will allocate full ring */
 			ret = vmxnet3_post_rx_bufs(rxq, j);
-			if (ret <= 0) {
+
+			/* Zero number of descriptors in the configuration of the RX queue */
+			if (ret == 0) {
 				PMD_INIT_LOG(ERR,
-					     "ERROR: Posting Rxq: %d buffers ring: %d",
-					     i, j);
-				return -ret;
+					"Invalid configuration in Rx queue: %d, buffers ring: %d\n",
+					i, j);
+				return -EINVAL;
+			}
+			/* Return the error number */
+			if (ret < 0) {
+				PMD_INIT_LOG(ERR, "Posting Rxq: %d buffers ring: %d", i, j);
+				return ret;
 			}
 			/*
 			 * Updating device with the index:next2fill to fill the
Signature · 1 line
2.30.2