netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: replace ternary operator with min()
@ 2022-10-23 13:07 KaiLong Wang
  2022-10-23 15:47 ` kernel test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: KaiLong Wang @ 2022-10-23 13:07 UTC (permalink / raw)
  To: davem, yoshfuji, dsahern, edumazet, kuba, pabeni; +Cc: netdev, linux-kernel

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@jari.cn>
---
 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-24 19:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-23 13:07 [PATCH] net: replace ternary operator with min() KaiLong Wang
2022-10-23 15:47 ` kernel test robot
2022-10-23 16:07 ` kernel test robot
2022-10-23 23:11 ` kernel test robot
2022-10-24 17:29 ` Jakub Kicinski

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).