[tip: objtool/core] klp-build: Use kzalloc_objs() for object and function arrays

From: tip-bot2 for Hungyu Lin

Date: Wed Nov 25 2026 - 03:41:00 EST


The following commit has been merged into the objtool/core branch of tip:

Commit-ID: 0397eb93362723345eb3a0ffbda0e19e654c0440
Gitweb: https://git.kernel.org/tip/0397eb93362723345eb3a0ffbda0e19e654c0440
Author: Hungyu Lin <dennylin0707@xxxxxxxxx>
AuthorDate: Tue, 20 Oct 2026 07:27:12
Committer: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
CommitterDate: Sat, 21 Nov 2026 23:38:32 -08:00

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 <dennylin0707@xxxxxxxxx>
Link: https://patch.msgid.link/20261020072712.12633-1-dennylin0707@xxxxxxxxx
Signed-off-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx>
---
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 16aff8f..df041fe 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++)