summaryrefslogtreecommitdiff
path: root/drivers/net/netdevsim/fib.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/fib.c
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlinux-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz
linux-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 'drivers/net/netdevsim/fib.c')
-rw-r--r--drivers/net/netdevsim/fib.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/drivers/net/netdevsim/fib.c b/drivers/net/netdevsim/fib.c
index 16c382c42227..b1292a8c0ef1 100644
--- a/drivers/net/netdevsim/fib.c
+++ b/drivers/net/netdevsim/fib.c
@@ -277,7 +277,7 @@ nsim_fib4_rt_create(struct nsim_fib_data *data,
{
struct nsim_fib4_rt *fib4_rt;
- fib4_rt = kzalloc(sizeof(*fib4_rt), GFP_KERNEL);
+ fib4_rt = kzalloc_obj(*fib4_rt, GFP_KERNEL);
if (!fib4_rt)
return NULL;
@@ -497,7 +497,7 @@ static int nsim_fib6_rt_nh_add(struct nsim_fib6_rt *fib6_rt,
{
struct nsim_fib6_rt_nh *fib6_rt_nh;
- fib6_rt_nh = kzalloc(sizeof(*fib6_rt_nh), GFP_KERNEL);
+ fib6_rt_nh = kzalloc_obj(*fib6_rt_nh, GFP_KERNEL);
if (!fib6_rt_nh)
return -ENOMEM;
@@ -544,7 +544,7 @@ nsim_fib6_rt_create(struct nsim_fib_data *data,
int i = 0;
int err;
- fib6_rt = kzalloc(sizeof(*fib6_rt), GFP_KERNEL);
+ fib6_rt = kzalloc_obj(*fib6_rt, GFP_KERNEL);
if (!fib6_rt)
return ERR_PTR(-ENOMEM);
@@ -807,7 +807,7 @@ static int nsim_fib6_event_init(struct nsim_fib6_event *fib6_event,
nrt6 = fen6_info->nsiblings + 1;
- rt_arr = kcalloc(nrt6, sizeof(struct fib6_info *), GFP_ATOMIC);
+ rt_arr = kzalloc_objs(struct fib6_info *, nrt6, GFP_ATOMIC);
if (!rt_arr)
return -ENOMEM;
@@ -987,7 +987,7 @@ static int nsim_fib_event_schedule_work(struct nsim_fib_data *data,
*/
return NOTIFY_DONE;
- fib_event = kzalloc(sizeof(*fib_event), GFP_ATOMIC);
+ fib_event = kzalloc_obj(*fib_event, GFP_ATOMIC);
if (!fib_event)
goto err_fib_event_alloc;
@@ -1116,7 +1116,7 @@ static struct nsim_nexthop *nsim_nexthop_create(struct nsim_fib_data *data,
u64 occ = 0;
int i;
- nexthop = kzalloc(sizeof(*nexthop), GFP_KERNEL);
+ nexthop = kzalloc_obj(*nexthop, GFP_KERNEL);
if (!nexthop)
return ERR_PTR(-ENOMEM);
@@ -1556,7 +1556,7 @@ struct nsim_fib_data *nsim_fib_create(struct devlink *devlink,
struct nsim_dev *nsim_dev;
int err;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return ERR_PTR(-ENOMEM);
data->devlink = devlink;