mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hungyu Lin <dennylin0707@gmail.com>
To: Josh Poimboeuf <jpoimboe@kernel.org>
Cc: Miroslav Benes <mbenes@suse.cz>, Petr Mladek <pmladek@suse.com>,
	Joe Lawrence <joe.lawrence@redhat.com>,
	Song Liu <song@kernel.org>,
	live-patching@vger.kernel.org, linux-kernel@vger.kernel.org,
	Hungyu Lin <dennylin0707@gmail.com>
Subject: [PATCH] klp-build: Use kzalloc_objs() for object and function arrays
Date: Tue, 20 Oct 2026 07:27:12 +0000	[thread overview]
Message-ID: <20261020072712.12633-1-dennylin0707@gmail.com> (raw)

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@gmail.com>
---
 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

                 reply	other threads:[~2026-10-20  7:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261020072712.12633-1-dennylin0707@gmail.com \
    --to=dennylin0707@gmail.com \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mbenes@suse.cz \
    --cc=pmladek@suse.com \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®