summaryrefslogtreecommitdiff
path: root/drivers/net/netdevsim/dev.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 /drivers/net/netdevsim/dev.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 'drivers/net/netdevsim/dev.c')
-rw-r--r--drivers/net/netdevsim/dev.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index f7b32446d3b8..a227c0b9fe4c 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -267,8 +267,8 @@ static ssize_t nsim_bus_dev_max_vfs_write(struct file *file,
if (val > NSIM_DEV_VF_PORT_INDEX_MAX - NSIM_DEV_VF_PORT_INDEX_BASE)
return -ERANGE;
- vfconfigs = kcalloc(val, sizeof(struct nsim_vf_config),
- GFP_KERNEL | __GFP_NOWARN);
+ vfconfigs = kzalloc_objs(struct nsim_vf_config, val,
+ GFP_KERNEL | __GFP_NOWARN);
if (!vfconfigs)
return -ENOMEM;
@@ -935,13 +935,13 @@ static int nsim_dev_traps_init(struct devlink *devlink)
struct nsim_trap_data *nsim_trap_data;
int err;
- nsim_trap_data = kzalloc(sizeof(*nsim_trap_data), GFP_KERNEL);
+ nsim_trap_data = kzalloc_obj(*nsim_trap_data, GFP_KERNEL);
if (!nsim_trap_data)
return -ENOMEM;
- nsim_trap_data->trap_items_arr = kcalloc(ARRAY_SIZE(nsim_traps_arr),
- sizeof(struct nsim_trap_item),
- GFP_KERNEL);
+ nsim_trap_data->trap_items_arr = kzalloc_objs(struct nsim_trap_item,
+ ARRAY_SIZE(nsim_traps_arr),
+ GFP_KERNEL);
if (!nsim_trap_data->trap_items_arr) {
err = -ENOMEM;
goto err_trap_data_free;
@@ -1348,7 +1348,7 @@ static int nsim_rate_node_new(struct devlink_rate *node, void **priv,
return -EOPNOTSUPP;
}
- nsim_node = kzalloc(sizeof(*nsim_node), GFP_KERNEL);
+ nsim_node = kzalloc_obj(*nsim_node, GFP_KERNEL);
if (!nsim_node)
return -ENOMEM;
@@ -1464,7 +1464,7 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, enum nsim_dev_port_typ
if (type == NSIM_DEV_PORT_TYPE_VF && !nsim_dev_get_vfs(nsim_dev))
return -EINVAL;
- nsim_dev_port = kzalloc(sizeof(*nsim_dev_port), GFP_KERNEL);
+ nsim_dev_port = kzalloc_obj(*nsim_dev_port, GFP_KERNEL);
if (!nsim_dev_port)
return -ENOMEM;
nsim_dev_port->port_index = nsim_dev_port_index(type, port_index);
@@ -1652,9 +1652,9 @@ int nsim_drv_probe(struct nsim_bus_dev *nsim_bus_dev)
dev_set_drvdata(&nsim_bus_dev->dev, nsim_dev);
- nsim_dev->vfconfigs = kcalloc(nsim_bus_dev->max_vfs,
- sizeof(struct nsim_vf_config),
- GFP_KERNEL | __GFP_NOWARN);
+ nsim_dev->vfconfigs = kzalloc_objs(struct nsim_vf_config,
+ nsim_bus_dev->max_vfs,
+ GFP_KERNEL | __GFP_NOWARN);
if (!nsim_dev->vfconfigs) {
err = -ENOMEM;
goto err_devlink_unlock;