diff mbox series

[net-next,7/8] tipc: use min() to simplify the code

Message ID 20240822133908.1042240-8-lizetao1@huawei.com
State Accepted
Commit a18308623ce303a0f8954294f3877b3ece8c5e7b
Headers show
Series Some modifications to optimize code readability | expand

Commit Message

Li Zetao Aug. 22, 2024, 1:39 p.m. UTC
When calculating size of own domain based on number of peers, the result
should be less than MAX_MON_DOMAIN, so using min() here is very semantic.

Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 net/tipc/monitor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Horman Aug. 24, 2024, 6:03 p.m. UTC | #1
On Thu, Aug 22, 2024 at 09:39:07PM +0800, Li Zetao wrote:
> When calculating size of own domain based on number of peers, the result
> should be less than MAX_MON_DOMAIN, so using min() here is very semantic.
> 
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
>  net/tipc/monitor.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> 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);
>  }

Perhaps this whole function is open coding something, but
if so I couldn't find it.

In any case this looks safe to me as i is an unsigned int
while MAX_MON_DOMAIN is 64 (also an unsigned int, I believe).

And the code being replaced appears to be a min() operation
in both form and function.

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

>  
>  static void map_set(u64 *up_map, int i, unsigned int v)
> -- 
> 2.34.1
> 
>
diff mbox series

Patch

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)