From 69050f8d6d075dc01af7a5f2f550a8067510366f Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Fri, 20 Feb 2026 23:49:23 -0800 Subject: 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 --- net/802/garp.c | 4 ++-- net/802/mrp.c | 4 ++-- net/802/psnap.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'net/802') 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; -- cgit v1.2.3