[PATCH] klp-build: Use kzalloc_objs() for object and function arrays
From: Hungyu Lin
Date: Tue Oct 20 2026 - 03:31:29 EST
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 <dennylin0707@xxxxxxxxx>
---
scripts/livepatch/init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/livepatch/init.c b/scripts/livepatch/init.c
index f14d8c8fb35f..908676d6d07d 100644
--- a/scripts/livepatch/init.c
+++ b/scripts/livepatch/init.c
@@ -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