summaryrefslogtreecommitdiff
path: root/net/netlink/genetlink.c
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/netlink/genetlink.c
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlwn-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz
lwn-69050f8d6d075dc01af7a5f2f550a8067510366f.zip
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/netlink/genetlink.c')
-rw-r--r--net/netlink/genetlink.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 978c129c6095..ac1fdf7d7327 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -659,7 +659,7 @@ static int genl_sk_privs_alloc(struct genl_family *family)
if (!family->sock_priv_size)
return 0;
- family->sock_privs = kzalloc(sizeof(*family->sock_privs), GFP_KERNEL);
+ family->sock_privs = kzalloc_obj(*family->sock_privs, GFP_KERNEL);
if (!family->sock_privs)
return -ENOMEM;
xa_init(family->sock_privs);
@@ -912,7 +912,7 @@ EXPORT_SYMBOL(genlmsg_put);
static struct genl_dumpit_info *genl_dumpit_info_alloc(void)
{
- return kmalloc(sizeof(struct genl_dumpit_info), GFP_KERNEL);
+ return kmalloc_obj(struct genl_dumpit_info, GFP_KERNEL);
}
static void genl_dumpit_info_free(const struct genl_dumpit_info *info)
@@ -937,8 +937,7 @@ genl_family_rcv_msg_attrs_parse(const struct genl_family *family,
if (!ops->maxattr)
return NULL;
- attrbuf = kmalloc_array(ops->maxattr + 1,
- sizeof(struct nlattr *), GFP_KERNEL);
+ attrbuf = kmalloc_objs(struct nlattr *, ops->maxattr + 1, GFP_KERNEL);
if (!attrbuf)
return ERR_PTR(-ENOMEM);
@@ -1591,7 +1590,7 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
return 0;
}
- ctx->op_iter = kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL);
+ ctx->op_iter = kmalloc_obj(*ctx->op_iter, GFP_KERNEL);
if (!ctx->op_iter)
return -ENOMEM;