summaryrefslogtreecommitdiff
path: root/net/bridge
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /net/bridge
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to avoid scalar types (which need careful case-by-case checking), and instead replace kmalloc-family calls that allocate struct or union object instances: Single allocations: kmalloc(sizeof(TYPE), ...) are replaced with: kmalloc_obj(TYPE, ...) Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...) are replaced with: kmalloc_objs(TYPE, COUNT, ...) Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...) are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...) (where TYPE may also be *VAR) The resulting allocations no longer return "void *", instead returning "TYPE *". Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'net/bridge')
-rw-r--r--net/bridge/br_cfm.c4
-rw-r--r--net/bridge/br_device.c2
-rw-r--r--net/bridge/br_if.c2
-rw-r--r--net/bridge/br_ioctl.c4
-rw-r--r--net/bridge/br_mdb.c4
-rw-r--r--net/bridge/br_mrp.c2
-rw-r--r--net/bridge/br_multicast.c8
-rw-r--r--net/bridge/br_multicast_eht.c6
-rw-r--r--net/bridge/br_switchdev.c2
-rw-r--r--net/bridge/br_vlan.c8
-rw-r--r--net/bridge/netfilter/ebtables.c2
11 files changed, 22 insertions, 22 deletions
diff --git a/net/bridge/br_cfm.c b/net/bridge/br_cfm.c
index c2c1c7d44c61..a2276ce350fa 100644
--- a/net/bridge/br_cfm.c
+++ b/net/bridge/br_cfm.c
@@ -547,7 +547,7 @@ int br_cfm_mep_create(struct net_bridge *br,
}
}
- mep = kzalloc(sizeof(*mep), GFP_KERNEL);
+ mep = kzalloc_obj(*mep, GFP_KERNEL);
if (!mep)
return -ENOMEM;
@@ -693,7 +693,7 @@ int br_cfm_cc_peer_mep_add(struct net_bridge *br, const u32 instance,
return -EEXIST;
}
- peer_mep = kzalloc(sizeof(*peer_mep), GFP_KERNEL);
+ peer_mep = kzalloc_obj(*peer_mep, GFP_KERNEL);
if (!peer_mep)
return -ENOMEM;
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index a818fdc22da9..1a3bcb5dd955 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -308,7 +308,7 @@ static int __br_netpoll_enable(struct net_bridge_port *p)
struct netpoll *np;
int err;
- np = kzalloc(sizeof(*p->np), GFP_KERNEL);
+ np = kzalloc_obj(*p->np, GFP_KERNEL);
if (!np)
return -ENOMEM;
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index 4c67a32745f6..4737ee16bebb 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -429,7 +429,7 @@ static struct net_bridge_port *new_nbp(struct net_bridge *br,
if (index < 0)
return ERR_PTR(index);
- p = kzalloc(sizeof(*p), GFP_KERNEL);
+ p = kzalloc_obj(*p, GFP_KERNEL);
if (p == NULL)
return ERR_PTR(-ENOMEM);
diff --git a/net/bridge/br_ioctl.c b/net/bridge/br_ioctl.c
index 6bc0a11f2ed3..7245ca29c5ea 100644
--- a/net/bridge/br_ioctl.c
+++ b/net/bridge/br_ioctl.c
@@ -204,7 +204,7 @@ int br_dev_siocdevprivate(struct net_device *dev, struct ifreq *rq,
if (num > BR_MAX_PORTS)
num = BR_MAX_PORTS;
- indices = kcalloc(num, sizeof(int), GFP_KERNEL);
+ indices = kzalloc_objs(int, num, GFP_KERNEL);
if (indices == NULL)
return -ENOMEM;
@@ -357,7 +357,7 @@ static int old_deviceless(struct net *net, void __user *data)
if (args[2] >= 2048)
return -ENOMEM;
- indices = kcalloc(args[2], sizeof(int), GFP_KERNEL);
+ indices = kzalloc_objs(int, args[2], GFP_KERNEL);
if (indices == NULL)
return -ENOMEM;
diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
index 400eb872b403..a5f0b74b59f3 100644
--- a/net/bridge/br_mdb.c
+++ b/net/bridge/br_mdb.c
@@ -1133,8 +1133,8 @@ static int br_mdb_config_src_list_init(struct nlattr *src_list,
return -EINVAL;
}
- cfg->src_entries = kcalloc(cfg->num_src_entries,
- sizeof(struct br_mdb_src_entry), GFP_KERNEL);
+ cfg->src_entries = kzalloc_objs(struct br_mdb_src_entry,
+ cfg->num_src_entries, GFP_KERNEL);
if (!cfg->src_entries)
return -ENOMEM;
diff --git a/net/bridge/br_mrp.c b/net/bridge/br_mrp.c
index 3c36fa24bc05..d587f99afef6 100644
--- a/net/bridge/br_mrp.c
+++ b/net/bridge/br_mrp.c
@@ -516,7 +516,7 @@ int br_mrp_add(struct net_bridge *br, struct br_mrp_instance *instance)
!br_mrp_unique_ifindex(br, instance->s_ifindex))
return -EINVAL;
- mrp = kzalloc(sizeof(*mrp), GFP_KERNEL);
+ mrp = kzalloc_obj(*mrp, GFP_KERNEL);
if (!mrp)
return -ENOMEM;
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index b6a5147886ca..881d866d687a 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -1290,7 +1290,7 @@ struct net_bridge_mdb_entry *br_multicast_new_group(struct net_bridge *br,
return ERR_PTR(-E2BIG);
}
- mp = kzalloc(sizeof(*mp), GFP_ATOMIC);
+ mp = kzalloc_obj(*mp, GFP_ATOMIC);
if (unlikely(!mp))
return ERR_PTR(-ENOMEM);
@@ -1381,7 +1381,7 @@ br_multicast_new_group_src(struct net_bridge_port_group *pg, struct br_ip *src_i
#endif
}
- grp_src = kzalloc(sizeof(*grp_src), GFP_ATOMIC);
+ grp_src = kzalloc_obj(*grp_src, GFP_ATOMIC);
if (unlikely(!grp_src))
return NULL;
@@ -1414,7 +1414,7 @@ struct net_bridge_port_group *br_multicast_new_port_group(
if (err)
return NULL;
- p = kzalloc(sizeof(*p), GFP_ATOMIC);
+ p = kzalloc_obj(*p, GFP_ATOMIC);
if (unlikely(!p)) {
NL_SET_ERR_MSG_MOD(extack, "Couldn't allocate new port group");
goto dec_out;
@@ -4891,7 +4891,7 @@ int br_multicast_list_adjacent(struct net_device *dev,
continue;
hlist_for_each_entry_rcu(group, &port->mglist, mglist) {
- entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
+ entry = kmalloc_obj(*entry, GFP_ATOMIC);
if (!entry)
goto unlock;
diff --git a/net/bridge/br_multicast_eht.c b/net/bridge/br_multicast_eht.c
index adfd74102019..18eaf9c0dada 100644
--- a/net/bridge/br_multicast_eht.c
+++ b/net/bridge/br_multicast_eht.c
@@ -266,7 +266,7 @@ __eht_lookup_create_host(struct net_bridge_port_group *pg,
if (br_multicast_eht_hosts_over_limit(pg))
return NULL;
- eht_host = kzalloc(sizeof(*eht_host), GFP_ATOMIC);
+ eht_host = kzalloc_obj(*eht_host, GFP_ATOMIC);
if (!eht_host)
return NULL;
@@ -313,7 +313,7 @@ __eht_lookup_create_set_entry(struct net_bridge *br,
if (!allow_zero_src && eht_host->num_entries >= PG_SRC_ENT_LIMIT)
return NULL;
- set_h = kzalloc(sizeof(*set_h), GFP_ATOMIC);
+ set_h = kzalloc_obj(*set_h, GFP_ATOMIC);
if (!set_h)
return NULL;
@@ -360,7 +360,7 @@ __eht_lookup_create_set(struct net_bridge_port_group *pg,
return this;
}
- eht_set = kzalloc(sizeof(*eht_set), GFP_ATOMIC);
+ eht_set = kzalloc_obj(*eht_set, GFP_ATOMIC);
if (!eht_set)
return NULL;
diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c
index fe3f7bbe86ee..4fac002922d2 100644
--- a/net/bridge/br_switchdev.c
+++ b/net/bridge/br_switchdev.c
@@ -661,7 +661,7 @@ void br_switchdev_mdb_notify(struct net_device *dev,
mdb.obj.orig_dev = pg->key.port->dev;
switch (type) {
case RTM_NEWMDB:
- complete_info = kmalloc(sizeof(*complete_info), GFP_ATOMIC);
+ complete_info = kmalloc_obj(*complete_info, GFP_ATOMIC);
if (!complete_info)
break;
complete_info->port = pg->key.port;
diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c
index ce72b837ff8e..e3a5eb9e6ed1 100644
--- a/net/bridge/br_vlan.c
+++ b/net/bridge/br_vlan.c
@@ -787,7 +787,7 @@ int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags, bool *changed,
return br_vlan_add_existing(br, vg, vlan, flags, changed,
extack);
- vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
+ vlan = kzalloc_obj(*vlan, GFP_KERNEL);
if (!vlan)
return -ENOMEM;
@@ -1224,7 +1224,7 @@ int br_vlan_init(struct net_bridge *br)
struct net_bridge_vlan_group *vg;
int ret = -ENOMEM;
- vg = kzalloc(sizeof(*vg), GFP_KERNEL);
+ vg = kzalloc_obj(*vg, GFP_KERNEL);
if (!vg)
goto out;
ret = rhashtable_init(&vg->vlan_hash, &br_vlan_rht_params);
@@ -1260,7 +1260,7 @@ int nbp_vlan_init(struct net_bridge_port *p, struct netlink_ext_ack *extack)
struct net_bridge_vlan_group *vg;
int ret = -ENOMEM;
- vg = kzalloc(sizeof(struct net_bridge_vlan_group), GFP_KERNEL);
+ vg = kzalloc_obj(struct net_bridge_vlan_group, GFP_KERNEL);
if (!vg)
goto out;
@@ -1334,7 +1334,7 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags,
return 0;
}
- vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
+ vlan = kzalloc_obj(*vlan, GFP_KERNEL);
if (!vlan)
return -ENOMEM;
diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
index a04fc1757528..f01efd0b139e 100644
--- a/net/bridge/netfilter/ebtables.c
+++ b/net/bridge/netfilter/ebtables.c
@@ -1303,7 +1303,7 @@ int ebt_register_template(const struct ebt_table *t, int (*table_init)(struct ne
}
}
- tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
+ tmpl = kzalloc_obj(*tmpl, GFP_KERNEL);
if (!tmpl) {
mutex_unlock(&ebt_mutex);
return -ENOMEM;