[PATCH nf-next] ipvs: use type-safe allocation helpers in ip_vs_rht_alloc

Subasri S posted 1 patch 1 week, 2 days ago
net/netfilter/ipvs/ip_vs_core.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
[PATCH nf-next] ipvs: use type-safe allocation helpers in ip_vs_rht_alloc
Posted by Subasri S 1 week, 2 days ago
As per Documentation/process/deprecated.rst, open-coded kmalloc
assignments for struct objects are deprecated. Replace
kzalloc(sizeof(*ptr), GFP_KERNEL) with kzalloc_obj() and
kvmalloc_array(n, sizeof(*ptr), GFP_KERNEL) with kvmalloc_objs()
in ip_vs_rht_alloc().

Compile tested with CONFIG_IP_VS=y and runtime tested using
tools/testing/selftests/net/netfilter/ipvs.sh on x86_64/QEMU.

Signed-off-by: Subasri S <subasris1210@gmail.com>
---
 net/netfilter/ipvs/ip_vs_core.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
index 35cbe821c259..74047bf1e32d 100644
--- a/net/netfilter/ipvs/ip_vs_core.c
+++ b/net/netfilter/ipvs/ip_vs_core.c
@@ -176,7 +176,7 @@ void ip_vs_rht_rcu_free(struct rcu_head *head)
 
 struct ip_vs_rht *ip_vs_rht_alloc(int buckets, int scounts, int locks)
 {
-	struct ip_vs_rht *t = kzalloc(sizeof(*t), GFP_KERNEL);
+	struct ip_vs_rht *t = kzalloc_obj(*t);
 	int i;
 
 	if (!t)
@@ -186,7 +186,7 @@ struct ip_vs_rht *ip_vs_rht_alloc(int buckets, int scounts, int locks)
 
 		scounts = min(scounts, buckets);
 		scounts = min(scounts, ml);
-		t->seqc = kvmalloc_array(scounts, sizeof(*t->seqc), GFP_KERNEL);
+		t->seqc = kvmalloc_objs(*t->seqc, scounts);
 		if (!t->seqc)
 			goto err;
 		for (i = 0; i < scounts; i++)
@@ -194,8 +194,7 @@ struct ip_vs_rht *ip_vs_rht_alloc(int buckets, int scounts, int locks)
 
 		if (locks) {
 			locks = min(locks, scounts);
-			t->lock = kvmalloc_array(locks, sizeof(*t->lock),
-						 GFP_KERNEL);
+			t->lock = kvmalloc_objs(*t->lock, locks);
 			if (!t->lock)
 				goto err;
 			for (i = 0; i < locks; i++)
@@ -203,7 +202,7 @@ struct ip_vs_rht *ip_vs_rht_alloc(int buckets, int scounts, int locks)
 		}
 	}
 
-	t->buckets = kvmalloc_array(buckets, sizeof(*t->buckets), GFP_KERNEL);
+	t->buckets = kvmalloc_objs(*t->buckets, buckets);
 	if (!t->buckets)
 		goto err;
 	for (i = 0; i < buckets; i++)

---
base-commit: f6f3b36c15ed44de1fbb44e645e4fae8c4a4453e
change-id: 20260714-nf-next-ipvs-deprecated-232667142d84

Best regards,
-- 
Subasri S <subasris1210@gmail.com>
Re: [PATCH nf-next] ipvs: use type-safe allocation helpers in ip_vs_rht_alloc
Posted by Julian Anastasov 3 days, 4 hours ago
	Hello,

On Thu, 16 Jul 2026, Subasri S wrote:

> As per Documentation/process/deprecated.rst, open-coded kmalloc
> assignments for struct objects are deprecated. Replace
> kzalloc(sizeof(*ptr), GFP_KERNEL) with kzalloc_obj() and
> kvmalloc_array(n, sizeof(*ptr), GFP_KERNEL) with kvmalloc_objs()
> in ip_vs_rht_alloc().
> 
> Compile tested with CONFIG_IP_VS=y and runtime tested using
> tools/testing/selftests/net/netfilter/ipvs.sh on x86_64/QEMU.
> 
> Signed-off-by: Subasri S <subasris1210@gmail.com>

	Looks good to me, thanks!

Acked-by: Julian Anastasov <ja@ssi.bg>

> ---
>  net/netfilter/ipvs/ip_vs_core.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
> index 35cbe821c259..74047bf1e32d 100644
> --- a/net/netfilter/ipvs/ip_vs_core.c
> +++ b/net/netfilter/ipvs/ip_vs_core.c
> @@ -176,7 +176,7 @@ void ip_vs_rht_rcu_free(struct rcu_head *head)
>  
>  struct ip_vs_rht *ip_vs_rht_alloc(int buckets, int scounts, int locks)
>  {
> -	struct ip_vs_rht *t = kzalloc(sizeof(*t), GFP_KERNEL);
> +	struct ip_vs_rht *t = kzalloc_obj(*t);
>  	int i;
>  
>  	if (!t)
> @@ -186,7 +186,7 @@ struct ip_vs_rht *ip_vs_rht_alloc(int buckets, int scounts, int locks)
>  
>  		scounts = min(scounts, buckets);
>  		scounts = min(scounts, ml);
> -		t->seqc = kvmalloc_array(scounts, sizeof(*t->seqc), GFP_KERNEL);
> +		t->seqc = kvmalloc_objs(*t->seqc, scounts);
>  		if (!t->seqc)
>  			goto err;
>  		for (i = 0; i < scounts; i++)
> @@ -194,8 +194,7 @@ struct ip_vs_rht *ip_vs_rht_alloc(int buckets, int scounts, int locks)
>  
>  		if (locks) {
>  			locks = min(locks, scounts);
> -			t->lock = kvmalloc_array(locks, sizeof(*t->lock),
> -						 GFP_KERNEL);
> +			t->lock = kvmalloc_objs(*t->lock, locks);
>  			if (!t->lock)
>  				goto err;
>  			for (i = 0; i < locks; i++)
> @@ -203,7 +202,7 @@ struct ip_vs_rht *ip_vs_rht_alloc(int buckets, int scounts, int locks)
>  		}
>  	}
>  
> -	t->buckets = kvmalloc_array(buckets, sizeof(*t->buckets), GFP_KERNEL);
> +	t->buckets = kvmalloc_objs(*t->buckets, buckets);
>  	if (!t->buckets)
>  		goto err;
>  	for (i = 0; i < buckets; i++)
> 
> ---
> base-commit: f6f3b36c15ed44de1fbb44e645e4fae8c4a4453e
> change-id: 20260714-nf-next-ipvs-deprecated-232667142d84
> 
> Best regards,
> -- 
> Subasri S <subasris1210@gmail.com>

Regards

--
Julian Anastasov <ja@ssi.bg>
Re: [PATCH nf-next] ipvs: use type-safe allocation helpers in ip_vs_rht_alloc
Posted by Phil Sutter 1 week, 1 day ago
On Thu, Jul 16, 2026 at 07:37:10PM +0530, Subasri S wrote:
> As per Documentation/process/deprecated.rst, open-coded kmalloc
> assignments for struct objects are deprecated. Replace
> kzalloc(sizeof(*ptr), GFP_KERNEL) with kzalloc_obj() and
> kvmalloc_array(n, sizeof(*ptr), GFP_KERNEL) with kvmalloc_objs()
> in ip_vs_rht_alloc().
> 
> Compile tested with CONFIG_IP_VS=y and runtime tested using
> tools/testing/selftests/net/netfilter/ipvs.sh on x86_64/QEMU.
> 
> Signed-off-by: Subasri S <subasris1210@gmail.com>

Reviewed-by: Phil Sutter <phil@nwl.cc>