diff mbox series

[nf-next,v2,2/4] ipvs: Consistently use array_size() in ip_vs_conn_init()

Message ID 20230409-ipvs-cleanup-v2-2-204cd17da708@kernel.org (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ipvs: Cleanups for v6.4 | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers warning 1 maintainers not CCed: horms@verge.net.au
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 30 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Simon Horman April 11, 2023, 7:10 a.m. UTC
Consistently use array_size() to calculate the size of ip_vs_conn_tab
in bytes.

Flagged by Coccinelle:
 WARNING: array_size is already used (line 1498) to compute the same size

No functional change intended.
Compile tested only.

Signed-off-by: Simon Horman <horms@kernel.org>
---
v2
* Retain division by 1024, which was lost in v1
---
 net/netfilter/ipvs/ip_vs_conn.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Horatiu Vultur April 11, 2023, 11:34 a.m. UTC | #1
The 04/11/2023 09:10, Simon Horman wrote:
> 
> Consistently use array_size() to calculate the size of ip_vs_conn_tab
> in bytes.
> 
> Flagged by Coccinelle:
>  WARNING: array_size is already used (line 1498) to compute the same size
> 
> No functional change intended.
> Compile tested only.

Reviewed-by: Horatiu Vultur <horatiu.vultur@microchip.com>

> 
> Signed-off-by: Simon Horman <horms@kernel.org>
> ---
> v2
> * Retain division by 1024, which was lost in v1
> ---
>  net/netfilter/ipvs/ip_vs_conn.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
> index 13534e02346c..84d273a84dc8 100644
> --- a/net/netfilter/ipvs/ip_vs_conn.c
> +++ b/net/netfilter/ipvs/ip_vs_conn.c
> @@ -1481,6 +1481,7 @@ void __net_exit ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs)
> 
>  int __init ip_vs_conn_init(void)
>  {
> +       size_t tab_array_size;
>         int idx;
> 
>         /* Compute size and mask */
> @@ -1494,8 +1495,9 @@ int __init ip_vs_conn_init(void)
>         /*
>          * Allocate the connection hash table and initialize its list heads
>          */
> -       ip_vs_conn_tab = vmalloc(array_size(ip_vs_conn_tab_size,
> -                                           sizeof(*ip_vs_conn_tab)));
> +       tab_array_size = array_size(ip_vs_conn_tab_size,
> +                                   sizeof(*ip_vs_conn_tab));
> +       ip_vs_conn_tab = vmalloc(tab_array_size);
>         if (!ip_vs_conn_tab)
>                 return -ENOMEM;
> 
> @@ -1508,10 +1510,8 @@ int __init ip_vs_conn_init(void)
>                 return -ENOMEM;
>         }
> 
> -       pr_info("Connection hash table configured "
> -               "(size=%d, memory=%ldKbytes)\n",
> -               ip_vs_conn_tab_size,
> -               (long)(ip_vs_conn_tab_size*sizeof(*ip_vs_conn_tab))/1024);
> +       pr_info("Connection hash table configured (size=%d, memory=%zdKbytes)\n",
> +               ip_vs_conn_tab_size / 1024, tab_array_size);
>         IP_VS_DBG(0, "Each connection entry needs %zd bytes at least\n",
>                   sizeof(struct ip_vs_conn));
> 
> 
> --
> 2.30.2
>
diff mbox series

Patch

diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
index 13534e02346c..84d273a84dc8 100644
--- a/net/netfilter/ipvs/ip_vs_conn.c
+++ b/net/netfilter/ipvs/ip_vs_conn.c
@@ -1481,6 +1481,7 @@  void __net_exit ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs)
 
 int __init ip_vs_conn_init(void)
 {
+	size_t tab_array_size;
 	int idx;
 
 	/* Compute size and mask */
@@ -1494,8 +1495,9 @@  int __init ip_vs_conn_init(void)
 	/*
 	 * Allocate the connection hash table and initialize its list heads
 	 */
-	ip_vs_conn_tab = vmalloc(array_size(ip_vs_conn_tab_size,
-					    sizeof(*ip_vs_conn_tab)));
+	tab_array_size = array_size(ip_vs_conn_tab_size,
+				    sizeof(*ip_vs_conn_tab));
+	ip_vs_conn_tab = vmalloc(tab_array_size);
 	if (!ip_vs_conn_tab)
 		return -ENOMEM;
 
@@ -1508,10 +1510,8 @@  int __init ip_vs_conn_init(void)
 		return -ENOMEM;
 	}
 
-	pr_info("Connection hash table configured "
-		"(size=%d, memory=%ldKbytes)\n",
-		ip_vs_conn_tab_size,
-		(long)(ip_vs_conn_tab_size*sizeof(*ip_vs_conn_tab))/1024);
+	pr_info("Connection hash table configured (size=%d, memory=%zdKbytes)\n",
+		ip_vs_conn_tab_size / 1024, tab_array_size);
 	IP_VS_DBG(0, "Each connection entry needs %zd bytes at least\n",
 		  sizeof(struct ip_vs_conn));