Re: [PATCH 1/2] livepatch: Fix wrong index in funcs cleanup error path
Yafang Shao <[email protected]>
| Newsgroups | org.kernel.vger.live-patching |
|---|---|
| Message-ID | <CALOAHbBcQpEcy364KBjZ-MUr_Ry8y=Nn8_jnPYxgGXFmcADAdg@mail.gmail.com> |
On Sat, Aug 15, 2026 at 4:36 AM Song Liu <[email protected]> wrote: > > On Wed, Aug 12, 2026 at 8:04 PM Yafang Shao <[email protected]> wrote: > > > > In the object allocation loop, when kzalloc() for funcs fails, the > > cleanup loop uses `objs[i].funcs` instead of `objs[j].funcs`. Since > > `objs[i].funcs` is still NULL at that point, it repeatedly calls > > kfree(NULL) and leaks all previously allocated funcs arrays. > > > > Fixes: 59adee07b568 ("livepatch/klp-build: Add stub init code for livepatch modules") > > Signed-off-by: Yafang Shao <[email protected]> > > Acked-by: Song Liu <[email protected]> > > With a nitpick/comment below: > > > --- > > 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..77746984aa57 100644 > > --- a/scripts/livepatch/init.c > > +++ b/scripts/livepatch/init.c > > @@ -50,8 +50,6 @@ static int __init livepatch_mod_init(void) > > funcs = kzalloc(sizeof(struct klp_func) * (nr_funcs + 1), GFP_KERNEL); > > if (!funcs) { > > ret = -ENOMEM; > > - for (int j = 0; j < i; j++) > > - kfree(objs[i].funcs); > > We really just need to replace objs[i] with obj[j] here, right? right > I personally feel it is actually cleaner to keep the kfree() loop here. Sure, I will keep the loop here in the next version. > Current patch is correct as-is though, so this is really a nitpick. > -- Regards Yafang