Skip to content

Commit

Permalink
Merge branch 'some-modifications-to-optimize-code-readability'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jakub Kicinski committed Aug 26, 2024
2 parents 77f0cae + a183086 commit 5efc962
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 2 additions & 4 deletions net/caif/cfpkt_skbuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 3 additions & 2 deletions net/ipv6/mcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion net/tipc/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5efc962

Please sign in to comment.