summaryrefslogtreecommitdiff
path: root/net/devlink/rate.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/devlink/rate.c
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/devlink/rate.c')
-rw-r--r--net/devlink/rate.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/net/devlink/rate.c b/net/devlink/rate.c
index 0d68b5c477dc..8d8a688ad140 100644
--- a/net/devlink/rate.c
+++ b/net/devlink/rate.c
@@ -627,7 +627,7 @@ int devlink_nl_rate_new_doit(struct sk_buff *skb, struct genl_info *info)
else if (rate_node == ERR_PTR(-EINVAL))
return -EINVAL;
- rate_node = kzalloc(sizeof(*rate_node), GFP_KERNEL);
+ rate_node = kzalloc_obj(*rate_node, GFP_KERNEL);
if (!rate_node)
return -ENOMEM;
@@ -721,7 +721,7 @@ devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,
if (!IS_ERR(rate_node))
return ERR_PTR(-EEXIST);
- rate_node = kzalloc(sizeof(*rate_node), GFP_KERNEL);
+ rate_node = kzalloc_obj(*rate_node, GFP_KERNEL);
if (!rate_node)
return ERR_PTR(-ENOMEM);
@@ -766,7 +766,7 @@ int devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv,
if (WARN_ON(devlink_port->devlink_rate))
return -EBUSY;
- devlink_rate = kzalloc(sizeof(*devlink_rate), GFP_KERNEL);
+ devlink_rate = kzalloc_obj(*devlink_rate, GFP_KERNEL);
if (!devlink_rate)
return -ENOMEM;