[PATCH] RDMA: replace ternary operator with min()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fix the following coccicheck warnings:

drivers/infiniband/sw/siw/siw_cm.c:1326:11-12: WARNING opportunity for min()
drivers/infiniband/sw/siw/siw_cm.c:488:11-12: WARNING opportunity for min()
drivers/infiniband/hw/cxgb4/cm.c:217:14-15: WARNING opportunity for min()
drivers/infiniband/hw/cxgb4/cm.c:232:14-15: WARNING opportunity for min()

min() macro is defined in include/linux/minmax.h. It avoids multiple
evaluations of the arguments when non-constant and performs strict
type-checking.

Signed-off-by: Guo Zhengkui <guozhengkui@xxxxxxxx>
---
 drivers/infiniband/hw/cxgb4/cm.c   | 4 ++--
 drivers/infiniband/sw/siw/siw_cm.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index c16017f6e8db..167faa358800 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -214,7 +214,7 @@ static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
 		kfree_skb(skb);
 	else if (error == NET_XMIT_DROP)
 		return -ENOMEM;
-	return error < 0 ? error : 0;
+	return min(error, 0);
 }
 
 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
@@ -229,7 +229,7 @@ int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
 	error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
 	if (error < 0)
 		kfree_skb(skb);
-	return error < 0 ? error : 0;
+	return min(error, 0);
 }
 
 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
diff --git a/drivers/infiniband/sw/siw/siw_cm.c b/drivers/infiniband/sw/siw/siw_cm.c
index 17f34d584cd9..3f8181664050 100644
--- a/drivers/infiniband/sw/siw/siw_cm.c
+++ b/drivers/infiniband/sw/siw/siw_cm.c
@@ -485,7 +485,7 @@ static int siw_send_mpareqrep(struct siw_cep *cep, const void *pdata, u8 pd_len)
 
 	rv = kernel_sendmsg(s, &msg, iov, iovec_num + 1, mpa_len);
 
-	return rv < 0 ? rv : 0;
+	return min(rv, 0);
 }
 
 /*
@@ -1324,7 +1324,7 @@ static int kernel_bindconnect(struct socket *s, struct sockaddr *laddr,
 
 	rv = s->ops->connect(s, raddr, size, flags);
 
-	return rv < 0 ? rv : 0;
+	return min(rv, 0);
 }
 
 int siw_connect(struct iw_cm_id *id, struct iw_cm_conn_param *params)
-- 
2.20.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux