klp-build: Use kzalloc_objs() for object and function arrays
PATCH 1/1 klp-build: Use kzalloc_objs() for object and function arrays
Allocate the object and function arrays with kzalloc_objs() so their element sizes are derived from the destination types and multiplication overflow is handled by the allocation helper.
Keep the extra zeroed entry used to terminate each array. The default allocation flags remain GFP_KERNEL.
Signed-off-by Hungyu Lin <[email protected]>
--- scripts/livepatch/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/livepatch/init.c +2 -2
@@ -34,7 +34,7 @@ static int __init livepatch_mod_init(void) goto err; } - objs =kzalloc (sizeof (struct klp_object ) * (nr_objs +1 ),GFP_KERNEL ); + objs =kzalloc_objs (*objs, nr_objs +1 );if (!objs) { ret = -ENOMEM ; goto err_free_patch;
@@ -47,7 +47,7 @@ static int __init livepatch_mod_init(void)struct klp_func *funcs = objs[i].funcs;struct klp_object *obj = objs + i; - funcs =kzalloc (sizeof (struct klp_func ) * (nr_funcs +1 ),GFP_KERNEL ); + funcs =kzalloc_objs (*funcs, nr_funcs +1 );if (!funcs) { ret = -ENOMEM ;for (int j =0 ; j < i; j++)
base-commit: f663062d717eac2c01f77eaf321fa630528e672d