public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel•org>
To: Li Zetao <lizetao1@huawei•com>
Cc: davem@davemloft•net, edumazet@google•com, kuba@kernel•org,
	pabeni@redhat•com, marcel@holtmann•org, johan.hedberg@gmail•com,
	luiz.dentz@gmail•com, idryomov@gmail•com, xiubli@redhat•com,
	dsahern@kernel•org, trondmy@kernel•org, anna@kernel•org,
	chuck.lever@oracle•com, jlayton@kernel•org, neilb@suse•de,
	okorniev@redhat•com, Dai.Ngo@oracle•com, tom@talpey•com,
	jmaloy@redhat•com, ying.xue@windriver•com, linux@treblig•org,
	jacob.e.keller@intel•com, willemb@google•com, kuniyu@amazon•com,
	wuyun.abel@bytedance•com, quic_abchauha@quicinc•com,
	gouhao@uniontech•com, netdev@vger•kernel.org,
	linux-bluetooth@vger•kernel.org, ceph-devel@vger•kernel.org,
	linux-nfs@vger•kernel.org, tipc-discussion@lists•sourceforge.net
Subject: Re: [PATCH net-next 6/8] ipv6: mcast: use min() to simplify the code
Date: Sat, 24 Aug 2024 18:57:38 +0100	[thread overview]
Message-ID: <20240824175738.GO2164@kernel.org> (raw)
In-Reply-To: <20240822133908.1042240-7-lizetao1@huawei.com>

On Thu, Aug 22, 2024 at 09:39:06PM +0800, Li Zetao wrote:
> 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>
> ---
>  net/ipv6/mcast.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> 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;

Both count and psl->sl_count are unsigned int,
so this looks safe (and more correct than what it replaces, IMHO).

>  
> -	copycount = count < gsf->gf_numsrc ? count : gsf->gf_numsrc;
> +	copycount = min(count, gsf->gf_numsrc);

And gsf->gf_numsrc is a __u32, so min operating on it and
count looks safe to me.

Further, the code it replaces seems to be a max() operation in
both intent and function.

Reviewed-by: Simon Horman <horms@kernel•org>

>  	gsf->gf_numsrc = count;
>  	for (i = 0; i < copycount; i++) {
>  		struct sockaddr_in6 *psin6;
> -- 
> 2.34.1
> 
> 

  reply	other threads:[~2024-08-24 17:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22 13:39 [PATCH net-next 0/8] Some modifications to optimize code readability Li Zetao
2024-08-22 13:39 ` [PATCH net-next 1/8] atm: use min() to simplify the code Li Zetao
2024-08-22 13:39   ` Dr. David Alan Gilbert
2024-08-22 13:50     ` Li Zetao
2024-08-22 20:20       ` Jacob Keller
2024-08-22 13:39 ` [PATCH net-next 2/8] Bluetooth: " Li Zetao
2024-08-24 18:15   ` Simon Horman
2024-08-22 13:39 ` [PATCH net-next 3/8] net: caif: use max() " Li Zetao
2024-08-24 17:37   ` Simon Horman
2024-08-22 13:39 ` [PATCH net-next 4/8] libceph: use min() " Li Zetao
2024-08-24 18:12   ` Simon Horman
2024-08-25 16:21     ` Ilya Dryomov
2024-08-27  7:31       ` Ilya Dryomov
2024-08-22 13:39 ` [PATCH net-next 5/8] net: remove redundant judgments " Li Zetao
2024-08-24 18:16   ` Simon Horman
2024-08-22 13:39 ` [PATCH net-next 6/8] ipv6: mcast: use min() " Li Zetao
2024-08-24 17:57   ` Simon Horman [this message]
2024-08-22 13:39 ` [PATCH net-next 7/8] tipc: " Li Zetao
2024-08-24 18:03   ` Simon Horman
2024-08-22 13:39 ` [PATCH net-next 8/8] SUNRPC: " Li Zetao
2024-08-24 18:07   ` Simon Horman
2024-08-24 18:21     ` Chuck Lever
2024-08-24 18:33       ` Trond Myklebust
2024-08-26 17:00 ` [PATCH net-next 0/8] Some modifications to optimize code readability patchwork-bot+netdevbpf
2024-09-12 16:33 ` patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240824175738.GO2164@kernel.org \
    --to=horms@kernel$(echo .)org \
    --cc=Dai.Ngo@oracle$(echo .)com \
    --cc=anna@kernel$(echo .)org \
    --cc=ceph-devel@vger$(echo .)kernel.org \
    --cc=chuck.lever@oracle$(echo .)com \
    --cc=davem@davemloft$(echo .)net \
    --cc=dsahern@kernel$(echo .)org \
    --cc=edumazet@google$(echo .)com \
    --cc=gouhao@uniontech$(echo .)com \
    --cc=idryomov@gmail$(echo .)com \
    --cc=jacob.e.keller@intel$(echo .)com \
    --cc=jlayton@kernel$(echo .)org \
    --cc=jmaloy@redhat$(echo .)com \
    --cc=johan.hedberg@gmail$(echo .)com \
    --cc=kuba@kernel$(echo .)org \
    --cc=kuniyu@amazon$(echo .)com \
    --cc=linux-bluetooth@vger$(echo .)kernel.org \
    --cc=linux-nfs@vger$(echo .)kernel.org \
    --cc=linux@treblig$(echo .)org \
    --cc=lizetao1@huawei$(echo .)com \
    --cc=luiz.dentz@gmail$(echo .)com \
    --cc=marcel@holtmann$(echo .)org \
    --cc=neilb@suse$(echo .)de \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=okorniev@redhat$(echo .)com \
    --cc=pabeni@redhat$(echo .)com \
    --cc=quic_abchauha@quicinc$(echo .)com \
    --cc=tipc-discussion@lists$(echo .)sourceforge.net \
    --cc=tom@talpey$(echo .)com \
    --cc=trondmy@kernel$(echo .)org \
    --cc=willemb@google$(echo .)com \
    --cc=wuyun.abel@bytedance$(echo .)com \
    --cc=xiubli@redhat$(echo .)com \
    --cc=ying.xue@windriver$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox