* [PATCH] RDMA: replace ternary operator with min()
@ 2022-05-12 13:58 Guo Zhengkui
2022-05-12 14:11 ` Jason Gunthorpe
0 siblings, 1 reply; 3+ messages in thread
From: Guo Zhengkui @ 2022-05-12 13:58 UTC (permalink / raw)
To: Potnuri Bharat Teja, Jason Gunthorpe, Leon Romanovsky,
Bernard Metzler, open list:CXGB4 IWARP RNIC DRIVER (IW_CXGB4),
open list
Cc: zhengkui_guo, Guo Zhengkui
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@vivo.com>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] RDMA: replace ternary operator with min()
2022-05-12 13:58 [PATCH] RDMA: replace ternary operator with min() Guo Zhengkui
@ 2022-05-12 14:11 ` Jason Gunthorpe
2022-05-12 14:39 ` Guo Zhengkui
0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2022-05-12 14:11 UTC (permalink / raw)
To: Guo Zhengkui
Cc: Potnuri Bharat Teja, Leon Romanovsky, Bernard Metzler,
open list:CXGB4 IWARP RNIC DRIVER (IW_CXGB4),
open list, zhengkui_guo
On Thu, May 12, 2022 at 09:58:37PM +0800, Guo Zhengkui wrote:
> 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.
no, these are all error return patterns, if you want to change them to
something change them to
if (error < 0)
return error;
return 0;
Jason
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] RDMA: replace ternary operator with min()
2022-05-12 14:11 ` Jason Gunthorpe
@ 2022-05-12 14:39 ` Guo Zhengkui
0 siblings, 0 replies; 3+ messages in thread
From: Guo Zhengkui @ 2022-05-12 14:39 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Potnuri Bharat Teja, Leon Romanovsky, Bernard Metzler,
open list:CXGB4 IWARP RNIC DRIVER (IW_CXGB4),
open list, zhengkui_guo
On 2022/5/12 22:11, Jason Gunthorpe wrote:
> On Thu, May 12, 2022 at 09:58:37PM +0800, Guo Zhengkui wrote:
>> 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.
>
> no, these are all error return patterns, if you want to change them to
> something change them to
>
> if (error < 0)
> return error;
> return 0;
Do you mean we need to stress that they are error return patterns
instead of taking "minimum value" style code?
Zhengkui
>
> Jason
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-05-12 14:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12 13:58 [PATCH] RDMA: replace ternary operator with min() Guo Zhengkui
2022-05-12 14:11 ` Jason Gunthorpe
2022-05-12 14:39 ` Guo Zhengkui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).