Skip to content

Commit

Permalink
ipv6: mcast: use min() to simplify the code
Browse files Browse the repository at this point in the history
When coping sockaddr in ip6_mc_msfget(), the time of copies
depends on the minimum value between sl_count and gf_numsrc.
Using min() here is very semantic.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20240822133908.1042240-7-lizetao1@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Li Zetao authored and Jakub Kicinski committed Aug 26, 2024
1 parent b4985aa commit 26549da
Showing 1 changed file with 3 additions and 2 deletions.
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

0 comments on commit 26549da

Please sign in to comment.