summaryrefslogtreecommitdiff
path: root/net/802
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/802
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/802')
-rw-r--r--net/802/garp.c4
-rw-r--r--net/802/mrp.c4
-rw-r--r--net/802/psnap.c2
3 files changed, 5 insertions, 5 deletions
diff --git a/net/802/garp.c b/net/802/garp.c
index 2d1ffc4d9462..ceeb5f5fac02 100644
--- a/net/802/garp.c
+++ b/net/802/garp.c
@@ -547,7 +547,7 @@ static int garp_init_port(struct net_device *dev)
{
struct garp_port *port;
- port = kzalloc(sizeof(*port), GFP_KERNEL);
+ port = kzalloc_obj(*port, GFP_KERNEL);
if (!port)
return -ENOMEM;
rcu_assign_pointer(dev->garp_port, port);
@@ -581,7 +581,7 @@ int garp_init_applicant(struct net_device *dev, struct garp_application *appl)
}
err = -ENOMEM;
- app = kzalloc(sizeof(*app), GFP_KERNEL);
+ app = kzalloc_obj(*app, GFP_KERNEL);
if (!app)
goto err2;
diff --git a/net/802/mrp.c b/net/802/mrp.c
index 23a88305f900..f65c95d43a4e 100644
--- a/net/802/mrp.c
+++ b/net/802/mrp.c
@@ -832,7 +832,7 @@ static int mrp_init_port(struct net_device *dev)
{
struct mrp_port *port;
- port = kzalloc(sizeof(*port), GFP_KERNEL);
+ port = kzalloc_obj(*port, GFP_KERNEL);
if (!port)
return -ENOMEM;
rcu_assign_pointer(dev->mrp_port, port);
@@ -866,7 +866,7 @@ int mrp_init_applicant(struct net_device *dev, struct mrp_application *appl)
}
err = -ENOMEM;
- app = kzalloc(sizeof(*app), GFP_KERNEL);
+ app = kzalloc_obj(*app, GFP_KERNEL);
if (!app)
goto err2;
diff --git a/net/802/psnap.c b/net/802/psnap.c
index 389df460c8c4..8ae835e1cbae 100644
--- a/net/802/psnap.c
+++ b/net/802/psnap.c
@@ -132,7 +132,7 @@ struct datalink_proto *register_snap_client(const unsigned char *desc,
if (find_snap_client(desc))
goto out;
- proto = kmalloc(sizeof(*proto), GFP_ATOMIC);
+ proto = kmalloc_obj(*proto, GFP_ATOMIC);
if (proto) {
memcpy(proto->type, desc, 5);
proto->rcvfunc = rcvfunc;