Skip to content

Commit 5efc962

Browse files
committed
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/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 77f0cae + a183086 commit 5efc962

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

net/caif/cfpkt_skbuff.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,8 @@ struct cfpkt *cfpkt_append(struct cfpkt *dstpkt,
298298
if (unlikely(is_erronous(dstpkt) || is_erronous(addpkt))) {
299299
return dstpkt;
300300
}
301-
if (expectlen > addlen)
302-
neededtailspace = expectlen;
303-
else
304-
neededtailspace = addlen;
301+
302+
neededtailspace = max(expectlen, addlen);
305303

306304
if (dst->tail + neededtailspace > dst->end) {
307305
/* Create a dumplicate of 'dst' with more tail space */

net/ipv6/mcast.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,8 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
586586
const struct in6_addr *group;
587587
struct ipv6_mc_socklist *pmc;
588588
struct ip6_sf_socklist *psl;
589-
int i, count, copycount;
589+
unsigned int count;
590+
int i, copycount;
590591

591592
group = &((struct sockaddr_in6 *)&gsf->gf_group)->sin6_addr;
592593

@@ -610,7 +611,7 @@ int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
610611
psl = sock_dereference(pmc->sflist, sk);
611612
count = psl ? psl->sl_count : 0;
612613

613-
copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc;
614+
copycount = min(count, gsf->gf_numsrc);
614615
gsf->gf_numsrc = count;
615616
for (i = 0; i < copycount; i++) {
616617
struct sockaddr_in6 *psin6;

net/tipc/monitor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static int dom_size(int peers)
149149

150150
while ((i * i) < peers)
151151
i++;
152-
return i < MAX_MON_DOMAIN ? i : MAX_MON_DOMAIN;
152+
return min(i, MAX_MON_DOMAIN);
153153
}
154154

155155
static void map_set(u64 *up_map, int i, unsigned int v)

0 commit comments

Comments
 (0)