[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240824074033.2134514-5-lihongbo22@huawei.com>
Date: Sat, 24 Aug 2024 15:40:29 +0800
From: Hongbo Li <lihongbo22@...wei.com>
To: <johannes@...solutions.net>, <davem@...emloft.net>, <edumazet@...gle.com>,
<kuba@...nel.org>, <pabeni@...hat.com>, <allison.henderson@...cle.com>,
<dsahern@...nel.org>, <pshelar@....org>
CC: <linux-wireless@...r.kernel.org>, <netdev@...r.kernel.org>,
<rds-devel@....oracle.com>, <dccp@...r.kernel.org>, <dev@...nvswitch.org>,
<linux-afs@...ts.infradead.org>, <lihongbo22@...wei.com>
Subject: [PATCH net-next 4/8] net/core: Use min()/max() to simplify the code
Let's use min()/max() to simplify the code and fix the
Coccinelle/coccicheck warning.
Signed-off-by: Hongbo Li <lihongbo22@...wei.com>
---
net/core/pktgen.c | 6 ++----
net/core/sock.c | 2 +-
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/net/core/pktgen.c b/net/core/pktgen.c
index ea55a758a475..5d4d5ec4a126 100644
--- a/net/core/pktgen.c
+++ b/net/core/pktgen.c
@@ -2793,8 +2793,7 @@ static void pktgen_finalize_skb(struct pktgen_dev *pkt_dev, struct sk_buff *skb,
}
i = 0;
- frag_len = (datalen/frags) < PAGE_SIZE ?
- (datalen/frags) : PAGE_SIZE;
+ frag_len = min(datalen/frags, PAGE_SIZE);
while (datalen > 0) {
if (unlikely(!pkt_dev->page)) {
int node = numa_node_id();
@@ -2811,8 +2810,7 @@ static void pktgen_finalize_skb(struct pktgen_dev *pkt_dev, struct sk_buff *skb,
if (i == (frags - 1))
skb_frag_fill_page_desc(&skb_shinfo(skb)->frags[i],
pkt_dev->page, 0,
- (datalen < PAGE_SIZE ?
- datalen : PAGE_SIZE));
+ min(datalen, PAGE_SIZE));
else
skb_frag_fill_page_desc(&skb_shinfo(skb)->frags[i],
pkt_dev->page, 0, frag_len);
diff --git a/net/core/sock.c b/net/core/sock.c
index bbe4c58470c3..c9910f48903f 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3800,7 +3800,7 @@ int sock_prot_inuse_get(struct net *net, struct proto *prot)
for_each_possible_cpu(cpu)
res += per_cpu_ptr(net->core.prot_inuse, cpu)->val[idx];
- return res >= 0 ? res : 0;
+ return max(res, 0);
}
EXPORT_SYMBOL_GPL(sock_prot_inuse_get);
--
2.34.1
Powered by blists - more mailing lists