diff options
author | Jakub Kicinski <kuba@kernel.org> | 2024-08-26 09:48:53 -0700 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2024-08-26 09:48:54 -0700 |
commit | 5efc9623cfaef22b3492147bf76c2d4d8586c77f (patch) | |
tree | 69279fc5d2c04c5a875575c3173e1725f4a28031 | |
parent | 77f0caecf4e63fd7fb0533ea85d7e792f95c2251 (diff) | |
parent | a18308623ce303a0f8954294f3877b3ece8c5e7b (diff) |
Merge branch 'some-modifications-to-optimize-code-readability'
Li Zetao says:
====================
Some modifications to optimize code readability
This patchset is mainly optimized for readability in contexts where size
needs to be determined. By using min() or max(), or even directly
removing redundant judgments (such as the 5th patch), the code is more
consistent with the context.
====================
Link: https://patch.msgid.link/20240822133908.1042240-1-lizetao1@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r-- | net/caif/cfpkt_skbuff.c | 6 | ||||
-rw-r--r-- | net/ipv6/mcast.c | 5 | ||||
-rw-r--r-- | net/tipc/monitor.c | 2 |
3 files changed, 6 insertions, 7 deletions
diff --git a/net/caif/cfpkt_skbuff.c b/net/caif/cfpkt_skbuff.c index 2ae8cfa3df88..96236d21b18e 100644 --- a/net/caif/cfpkt_skbuff.c +++ b/net/caif/cfpkt_skbuff.c @@ -298,10 +298,8 @@ struct cfpkt *cfpkt_append(struct cfpkt *dstpkt, if (unlikely(is_erronous(dstpkt) || is_erronous(addpkt))) { return dstpkt; } - if (expectlen > addlen) - neededtailspace = expectlen; - else - neededtailspace = addlen; + + neededtailspace = max(expectlen, addlen); if (dst->tail + neededtailspace > dst->end) { /* Create a dumplicate of 'dst' with more tail space */ diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c index 7ba01d8cfbae..b244dbf61d5f 100644 --- a/net/ipv6/mcast.c +++ b/net/ipv6/mcast.c @@ -586,7 +586,8 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf, const struct in6_addr *group; struct ipv6_mc_socklist *pmc; struct ip6_sf_socklist *psl; - int i, count, copycount; + unsigned int count; + int i, copycount; group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr; @@ -610,7 +611,7 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf, psl = sock_dereference(pmc->sflist, sk); 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_in6 *psin6; diff --git a/net/tipc/monitor.c b/net/tipc/monitor.c index 77a3d016cade..e2f19627e43d 100644 --- a/net/tipc/monitor.c +++ b/net/tipc/monitor.c @@ -149,7 +149,7 @@ static int dom_size(int peers) while ((i * i) < peers) i++; - return i < MAX_MON_DOMAIN ? i : MAX_MON_DOMAIN; + return min(i, MAX_MON_DOMAIN); } static void map_set(u64 *up_map, int i, unsigned int v) |