Skip to contentSkip to conversation

Return ERRNO codes from ibv_post_send/recv instead of -1

PATCH/libmlx4 Jason Gunthorpe 3 participants 4 messages Mar 9, 2011 2 messages not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

The man pages for these functions document a positive return of errno not -1.

---
 src/qp.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

Noticed this.. What do you think?

I did not check the other drivers.

src/qp.c +7 -6
index d194ae3..ec138cd 100644
@@ -40,6 +40,7 @@
 #include <netinet/in.h>
 #include <pthread.h>
 #include <string.h>
+#include <errno.h>
 
 #include "mlx4.h"
 #include "doorbell.h"
@@ -206,19 +207,19 @@ int mlx4_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 
 	for (nreq = 0; wr; ++nreq, wr = wr->next) {
 		if (wq_overflow(&qp->sq, nreq, to_mcq(qp->ibv_qp.send_cq))) {
-			ret = -1;
+			ret = ENOMEM;
 			*bad_wr = wr;
 			goto out;
 		}
 
 		if (wr->num_sge > qp->sq.max_gs) {
-			ret = -1;
+			ret = ENOMEM;
 			*bad_wr = wr;
 			goto out;
 		}
 
 		if (wr->opcode >= sizeof mlx4_ib_opcode / sizeof mlx4_ib_opcode[0]) {
-			ret = -1;
+			ret = EINVAL;
 			*bad_wr = wr;
 			goto out;
 		}
@@ -309,7 +310,7 @@ int mlx4_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 
 				if (inl > qp->max_inline_data) {
 					inl = 0;
-					ret = -1;
+					ret = ENOMEM;
 					*bad_wr = wr;
 					goto out;
 				}
@@ -450,13 +451,13 @@ int mlx4_post_recv(struct ibv_qp *ibqp, struct ibv_recv_wr *wr,
 
 	for (nreq = 0; wr; ++nreq, wr = wr->next) {
 		if (wq_overflow(&qp->rq, nreq, to_mcq(qp->ibv_qp.recv_cq))) {
-			ret = -1;
+			ret = ENOMEM;
 			*bad_wr = wr;
 			goto out;
 		}
 
 		if (wr->num_sge > qp->rq.max_gs) {
-			ret = -1;
+			ret = ENOMEM;
 			*bad_wr = wr;
 			goto out;
 		}
Signature · 6 lines
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20110309012810.GM22729-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org

#2 lore raw

Returning an errno is always better than just returning -1. (Assuming it's an appropriate error number...)

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Jason Gunthorpe
Sent: Tuesday, March 08, 2011 8:28 PM
To: Roland Dreier; [email protected]
Subject: [PATCH/libmlx4] Return ERRNO codes from ibv_post_send/recv instead of -1

The man pages for these functions document a positive return of errno not -1.

---
 src/qp.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)

Noticed this.. What do you think?

I did not check the other drivers.

src/qp.c +7 -6
index d194ae3..ec138cd 100644
@@ -40,6 +40,7 @@
 #include <netinet/in.h>
 #include <pthread.h>
 #include <string.h>
+#include <errno.h>
 
 #include "mlx4.h"
 #include "doorbell.h"
@@ -206,19 +207,19 @@ int mlx4_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 
        for (nreq = 0; wr; ++nreq, wr = wr->next) {
                if (wq_overflow(&qp->sq, nreq, to_mcq(qp->ibv_qp.send_cq))) {
-                       ret = -1;
+                       ret = ENOMEM;
                        *bad_wr = wr;
                        goto out;
                }
 
                if (wr->num_sge > qp->sq.max_gs) {
-                       ret = -1;
+                       ret = ENOMEM;
                        *bad_wr = wr;
                        goto out;
                }
 
                if (wr->opcode >= sizeof mlx4_ib_opcode / sizeof mlx4_ib_opcode[0]) {
-                       ret = -1;
+                       ret = EINVAL;
                        *bad_wr = wr;
                        goto out;
                }
@@ -309,7 +310,7 @@ int mlx4_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
 
                                if (inl > qp->max_inline_data) {
                                        inl = 0;
-                                       ret = -1;
+                                       ret = ENOMEM;
                                        *bad_wr = wr;
                                        goto out;
                                }
@@ -450,13 +451,13 @@ int mlx4_post_recv(struct ibv_qp *ibqp, struct ibv_recv_wr *wr,
 
        for (nreq = 0; wr; ++nreq, wr = wr->next) {
                if (wq_overflow(&qp->rq, nreq, to_mcq(qp->ibv_qp.recv_cq))) {
-                       ret = -1;
+                       ret = ENOMEM;
                        *bad_wr = wr;
                        goto out;
                }
 
                if (wr->num_sge > qp->rq.max_gs) {
-                       ret = -1;
+                       ret = ENOMEM;
                        *bad_wr = wr;
                        goto out;
                }

--
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

This message and any attached documents contain information from QLogic Corporation or its wholly-owned subsidiaries that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to a message not in the archive
Quoted 2 lines · Jason Gunthorpe

-                       ret = -1;
+                       ret = ENOMEM;

I'm afraid that this will break any code that tests return values with the test "< 0". Introducing error codes is good, but why to change negative return codes into positive ?

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): AANLkTikfGw=ORf=B9x0Z8rrfnxOV=j0ynaSvRZ6j1sVt-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#5 lore raw
Quoted 8 lines · Bart Van Assche
Quoted 2 lines · Jason Gunthorpe

- ? ? ? ? ? ? ? ? ? ? ? ret = -1;
+ ? ? ? ? ? ? ? ? ? ? ? ret = ENOMEM;

I'm afraid that this will break any code that tests return values with the test "< 0". Introducing error codes is good, but why to change negative return codes into positive ?

Any code that checks for < 0 is already broken. This is just the mlx4 userspace driver, other drivers correctly return positive errno, eg any driver that uses the ibv_cmd_post_send path returns positive errno.

The standard convention for ibverbs, clearly stated in the manual is that 0 is success and everything else is errno.

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html