public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH] batman-adv: Switch to type-aware kmalloc-family helpers
Date: Mon, 16 Feb 2026 20:52:44 +0100	[thread overview]
Message-ID: <20260216-alloc_obj-v1-1-4d72b5f32e2d@narfation.org> (raw)

The commit 2932ba8d9c99 ("slab: Introduce kmalloc_obj() and family")
introduced helpers to provide type information to the allocator. At the
same time, the open-coding of kmalloc assignments was deprecated.

Use the new helpers to benefit from the future enhancements in the
allocator/validator infrastructure.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 compat-include/linux/slab.h            | 29 +++++++++++++++++++++++++++++
 compat-include/net/addrconf.h          |  2 +-
 net/batman-adv/bat_v_elp.c             |  2 +-
 net/batman-adv/bridge_loop_avoidance.c |  4 ++--
 net/batman-adv/distributed-arp-table.c |  5 ++---
 net/batman-adv/fragmentation.c         |  2 +-
 net/batman-adv/gateway_client.c        |  2 +-
 net/batman-adv/hard-interface.c        |  2 +-
 net/batman-adv/hash.c                  |  7 +++----
 net/batman-adv/mesh-interface.c        |  2 +-
 net/batman-adv/multicast.c             |  6 +++---
 net/batman-adv/originator.c            | 12 ++++++------
 net/batman-adv/send.c                  |  2 +-
 net/batman-adv/tp_meter.c              |  6 +++---
 net/batman-adv/tvlv.c                  |  2 +-
 15 files changed, 56 insertions(+), 29 deletions(-)

diff --git a/compat-include/linux/slab.h b/compat-include/linux/slab.h
new file mode 100644
index 00000000..4211278e
--- /dev/null
+++ b/compat-include/linux/slab.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (C) B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner, Simon Wunderlich
+ *
+ * This file contains macros for maintaining compatibility with older versions
+ * of the Linux kernel.
+ */
+
+#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_SLAB_H_
+#define _NET_BATMAN_ADV_COMPAT_LINUX_SLAB_H_
+
+#include <linux/version.h>
+#include_next <linux/slab.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(7, 1, 0)
+
+#define kzalloc_obj(P, GFP) \
+	kzalloc(sizeof(P), GFP)
+
+#define kmalloc_obj(P, GFP) \
+	kmalloc(sizeof(P), GFP)
+
+#define kmalloc_objs(P, COUNT, GFP) \
+	kmalloc_array((COUNT), sizeof(P), GFP)
+
+#endif /* < KERNEL_VERSION(7, 1, 0) */
+
+#endif	/* _NET_BATMAN_ADV_COMPAT_LINUX_SLAB_H_ */
diff --git a/compat-include/net/addrconf.h b/compat-include/net/addrconf.h
index f0a3c0a6..2e48813a 100644
--- a/compat-include/net/addrconf.h
+++ b/compat-include/net/addrconf.h
@@ -61,7 +61,7 @@ compat_batadv_mcast_mla_meshif_get_ipv6(struct net_device *dev,
 		if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list))
 			continue;
 
-		new = kmalloc(sizeof(*new), GFP_ATOMIC);
+		new = kmalloc_obj(*new, GFP_ATOMIC);
 		if (!new) {
 			ret = -ENOMEM;
 			break;
diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
index cb16c1ed..2ce4e5bf 100644
--- a/net/batman-adv/bat_v_elp.c
+++ b/net/batman-adv/bat_v_elp.c
@@ -355,7 +355,7 @@ static void batadv_v_elp_periodic_work(struct work_struct *work)
 		 * context. Therefore add it to metric_queue and process it
 		 * outside rcu protected context.
 		 */
-		metric_entry = kzalloc(sizeof(*metric_entry), GFP_ATOMIC);
+		metric_entry = kzalloc_obj(*metric_entry, GFP_ATOMIC);
 		if (!metric_entry) {
 			batadv_hardif_neigh_put(hardif_neigh);
 			continue;
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 3dc791c1..49ae92b9 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -505,7 +505,7 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, const u8 *orig,
 		   "%s(): not found (%pM, %d), creating new entry\n", __func__,
 		   orig, batadv_print_vid(vid));
 
-	entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
+	entry = kzalloc_obj(*entry, GFP_ATOMIC);
 	if (!entry)
 		return NULL;
 
@@ -699,7 +699,7 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
 
 	/* create a new claim entry if it does not exist yet. */
 	if (!claim) {
-		claim = kzalloc(sizeof(*claim), GFP_ATOMIC);
+		claim = kzalloc_obj(*claim, GFP_ATOMIC);
 		if (!claim)
 			return;
 
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index 8b8132eb..3efc4cf5 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -381,7 +381,7 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip,
 		goto out;
 	}
 
-	dat_entry = kmalloc(sizeof(*dat_entry), GFP_ATOMIC);
+	dat_entry = kmalloc_obj(*dat_entry, GFP_ATOMIC);
 	if (!dat_entry)
 		goto out;
 
@@ -635,8 +635,7 @@ batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst,
 	if (!bat_priv->orig_hash)
 		return NULL;
 
-	res = kmalloc_array(BATADV_DAT_CANDIDATES_NUM, sizeof(*res),
-			    GFP_ATOMIC);
+	res = kmalloc_objs(*res, BATADV_DAT_CANDIDATES_NUM, GFP_ATOMIC);
 	if (!res)
 		return NULL;
 
diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
index cc14bc41..f4e45cc2 100644
--- a/net/batman-adv/fragmentation.c
+++ b/net/batman-adv/fragmentation.c
@@ -156,7 +156,7 @@ static bool batadv_frag_insert_packet(struct batadv_orig_node *orig_node,
 	seqno = ntohs(frag_packet->seqno);
 	bucket = seqno % BATADV_FRAG_BUFFER_COUNT;
 
-	frag_entry_new = kmalloc(sizeof(*frag_entry_new), GFP_ATOMIC);
+	frag_entry_new = kmalloc_obj(*frag_entry_new, GFP_ATOMIC);
 	if (!frag_entry_new)
 		goto err;
 
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index 7a11b245..51e9c081 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -332,7 +332,7 @@ static void batadv_gw_node_add(struct batadv_priv *bat_priv,
 	if (gateway->bandwidth_down == 0)
 		return;
 
-	gw_node = kzalloc(sizeof(*gw_node), GFP_ATOMIC);
+	gw_node = kzalloc_obj(*gw_node, GFP_ATOMIC);
 	if (!gw_node)
 		return;
 
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 5113f879..7b7640f3 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -871,7 +871,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
 	if (!batadv_is_valid_iface(net_dev))
 		return NULL;
 
-	hard_iface = kzalloc(sizeof(*hard_iface), GFP_ATOMIC);
+	hard_iface = kzalloc_obj(*hard_iface, GFP_ATOMIC);
 	if (!hard_iface)
 		return NULL;
 
diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c
index 8016e619..759fa291 100644
--- a/net/batman-adv/hash.c
+++ b/net/batman-adv/hash.c
@@ -45,16 +45,15 @@ struct batadv_hashtable *batadv_hash_new(u32 size)
 {
 	struct batadv_hashtable *hash;
 
-	hash = kmalloc(sizeof(*hash), GFP_ATOMIC);
+	hash = kmalloc_obj(*hash, GFP_ATOMIC);
 	if (!hash)
 		return NULL;
 
-	hash->table = kmalloc_array(size, sizeof(*hash->table), GFP_ATOMIC);
+	hash->table = kmalloc_objs(*hash->table, size, GFP_ATOMIC);
 	if (!hash->table)
 		goto free_hash;
 
-	hash->list_locks = kmalloc_array(size, sizeof(*hash->list_locks),
-					 GFP_ATOMIC);
+	hash->list_locks = kmalloc_objs(*hash->list_locks, size, GFP_ATOMIC);
 	if (!hash->list_locks)
 		goto free_table;
 
diff --git a/net/batman-adv/mesh-interface.c b/net/batman-adv/mesh-interface.c
index 9d72fcdc..50c26037 100644
--- a/net/batman-adv/mesh-interface.c
+++ b/net/batman-adv/mesh-interface.c
@@ -555,7 +555,7 @@ int batadv_meshif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
 		return -EEXIST;
 	}
 
-	vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC);
+	vlan = kzalloc_obj(*vlan, GFP_ATOMIC);
 	if (!vlan) {
 		spin_unlock_bh(&bat_priv->meshif_vlan_list_lock);
 		return -ENOMEM;
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index 2d5244a1..7dba0c2b 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -406,7 +406,7 @@ batadv_mcast_mla_meshif_get_ipv4(struct net_device *dev,
 		if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list))
 			continue;
 
-		new = kmalloc(sizeof(*new), GFP_ATOMIC);
+		new = kmalloc_obj(*new, GFP_ATOMIC);
 		if (!new) {
 			ret = -ENOMEM;
 			break;
@@ -479,7 +479,7 @@ batadv_mcast_mla_meshif_get_ipv6(struct net_device *dev,
 		if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list))
 			continue;
 
-		new = kmalloc(sizeof(*new), GFP_ATOMIC);
+		new = kmalloc_obj(*new, GFP_ATOMIC);
 		if (!new) {
 			ret = -ENOMEM;
 			break;
@@ -639,7 +639,7 @@ static int batadv_mcast_mla_bridge_get(struct net_device *dev,
 		if (batadv_mcast_mla_is_duplicate(mcast_addr, mcast_list))
 			continue;
 
-		new = kmalloc(sizeof(*new), GFP_ATOMIC);
+		new = kmalloc_obj(*new, GFP_ATOMIC);
 		if (!new) {
 			ret = -ENOMEM;
 			break;
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index a662408a..b3468cca 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -179,7 +179,7 @@ batadv_orig_node_vlan_new(struct batadv_orig_node *orig_node,
 	if (vlan)
 		goto out;
 
-	vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC);
+	vlan = kzalloc_obj(*vlan, GFP_ATOMIC);
 	if (!vlan)
 		goto out;
 
@@ -417,7 +417,7 @@ batadv_orig_ifinfo_new(struct batadv_orig_node *orig_node,
 	if (orig_ifinfo)
 		goto out;
 
-	orig_ifinfo = kzalloc(sizeof(*orig_ifinfo), GFP_ATOMIC);
+	orig_ifinfo = kzalloc_obj(*orig_ifinfo, GFP_ATOMIC);
 	if (!orig_ifinfo)
 		goto out;
 
@@ -495,7 +495,7 @@ batadv_neigh_ifinfo_new(struct batadv_neigh_node *neigh,
 	if (neigh_ifinfo)
 		goto out;
 
-	neigh_ifinfo = kzalloc(sizeof(*neigh_ifinfo), GFP_ATOMIC);
+	neigh_ifinfo = kzalloc_obj(*neigh_ifinfo, GFP_ATOMIC);
 	if (!neigh_ifinfo)
 		goto out;
 
@@ -575,7 +575,7 @@ batadv_hardif_neigh_create(struct batadv_hard_iface *hard_iface,
 	if (hardif_neigh)
 		goto out;
 
-	hardif_neigh = kzalloc(sizeof(*hardif_neigh), GFP_ATOMIC);
+	hardif_neigh = kzalloc_obj(*hardif_neigh, GFP_ATOMIC);
 	if (!hardif_neigh)
 		goto out;
 
@@ -683,7 +683,7 @@ batadv_neigh_node_create(struct batadv_orig_node *orig_node,
 	if (!hardif_neigh)
 		goto out;
 
-	neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC);
+	neigh_node = kzalloc_obj(*neigh_node, GFP_ATOMIC);
 	if (!neigh_node)
 		goto out;
 
@@ -947,7 +947,7 @@ struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
 	batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
 		   "Creating new originator: %pM\n", addr);
 
-	orig_node = kzalloc(sizeof(*orig_node), GFP_ATOMIC);
+	orig_node = kzalloc_obj(*orig_node, GFP_ATOMIC);
 	if (!orig_node)
 		return NULL;
 
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 20d85c68..60cd67ec 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -503,7 +503,7 @@ batadv_forw_packet_alloc(struct batadv_hard_iface *if_incoming,
 		return NULL;
 	}
 
-	forw_packet = kmalloc(sizeof(*forw_packet), GFP_ATOMIC);
+	forw_packet = kmalloc_obj(*forw_packet, GFP_ATOMIC);
 	if (!forw_packet)
 		goto err;
 
diff --git a/net/batman-adv/tp_meter.c b/net/batman-adv/tp_meter.c
index 350b149e..2e42f6b3 100644
--- a/net/batman-adv/tp_meter.c
+++ b/net/batman-adv/tp_meter.c
@@ -967,7 +967,7 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,
 		return;
 	}
 
-	tp_vars = kmalloc(sizeof(*tp_vars), GFP_ATOMIC);
+	tp_vars = kmalloc_obj(*tp_vars, GFP_ATOMIC);
 	if (!tp_vars) {
 		spin_unlock_bh(&bat_priv->tp_list_lock);
 		batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
@@ -1228,7 +1228,7 @@ static bool batadv_tp_handle_out_of_order(struct batadv_tp_vars *tp_vars,
 	u32 payload_len;
 	bool added = false;
 
-	new = kmalloc(sizeof(*new), GFP_ATOMIC);
+	new = kmalloc_obj(*new, GFP_ATOMIC);
 	if (unlikely(!new))
 		return false;
 
@@ -1343,7 +1343,7 @@ batadv_tp_init_recv(struct batadv_priv *bat_priv,
 		goto out_unlock;
 	}
 
-	tp_vars = kmalloc(sizeof(*tp_vars), GFP_ATOMIC);
+	tp_vars = kmalloc_obj(*tp_vars, GFP_ATOMIC);
 	if (!tp_vars)
 		goto out_unlock;
 
diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
index 76dff1f9..8129a3f9 100644
--- a/net/batman-adv/tvlv.c
+++ b/net/batman-adv/tvlv.c
@@ -557,7 +557,7 @@ void batadv_tvlv_handler_register(struct batadv_priv *bat_priv,
 		return;
 	}
 
-	tvlv_handler = kzalloc(sizeof(*tvlv_handler), GFP_ATOMIC);
+	tvlv_handler = kzalloc_obj(*tvlv_handler, GFP_ATOMIC);
 	if (!tvlv_handler) {
 		spin_unlock_bh(&bat_priv->tvlv.handler_list_lock);
 		return;

---
base-commit: 35208d1234584c536db431441445ce82f09273f6
change-id: 20260216-alloc_obj-d15ba4f6032e

Best regards,
-- 
Sven Eckelmann <sven@narfation.org>


                 reply	other threads:[~2026-02-16 19:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260216-alloc_obj-v1-1-4d72b5f32e2d@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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