[PATCH] net: replace ternary operator with min()
From: KaiLong Wang
Date: Sun Oct 23 2022 - 09:11:57 EST
Fix the following coccicheck warning:
net/ipv4/igmp.c:2621: WARNING opportunity for min()
net/ipv4/igmp.c:2574: WARNING opportunity for min()
net/ipv4/ip_sockglue.c:285: WARNING opportunity for min()
Signed-off-by: KaiLong Wang <wangkailong@xxxxxxx>
---
net/ipv4/igmp.c | 4 ++--
net/ipv4/ip_sockglue.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 81be3e0f0e70..7939d8febb2b 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -2571,7 +2571,7 @@ int ip_mc_msfget(struct sock *sk, struct ip_msfilter *msf,
} else {
count = psl->sl_count;
}
- copycount = count < msf->imsf_numsrc ? count : msf->imsf_numsrc;
+ copycount = min(count, msf->imsf_numsrc);
len = flex_array_size(psl, sl_addr, copycount);
msf->imsf_numsrc = count;
msf_size = IP_MSFILTER_SIZE(copycount);
@@ -2618,7 +2618,7 @@ int ip_mc_gsfget(struct sock *sk, struct group_filter *gsf,
gsf->gf_fmode = pmc->sfmode;
psl = rtnl_dereference(pmc->sflist);
count = psl ? psl->sl_count : 0;
- copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc;
+ copycount = min(count, gsf->gf_numsrc);
gsf->gf_numsrc = count;
for (i = 0; i < copycount; i++) {
struct sockaddr_storage ss;
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index 6e19cad154f5..19ad37897227 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -282,7 +282,7 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
/* Our caller is responsible for freeing ipc->opt */
err = ip_options_get(net, &ipc->opt,
KERNEL_SOCKPTR(CMSG_DATA(cmsg)),
- err < 40 ? err : 40);
+ min(err, 40));
if (err)
return err;
break;
--
2.25.1