Re: [rtla 01/13] rtla: Check for memory allocation failures

From: Google
Date: Tue Nov 18 2025 - 00:14:05 EST


On Mon, 17 Nov 2025 22:06:15 -0500
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> On Tue, 18 Nov 2025 11:09:46 +0900
> Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx> wrote:
>
> > On Mon, 17 Nov 2025 15:41:08 -0300
> > Wander Lairson Costa <wander@xxxxxxxxxx> wrote:
> >
> > > The actions_init() and actions_new() functions did not check the
> > > return value of calloc() and realloc() respectively. In a low
> > > memory situation, this could lead to a NULL pointer dereference.
> > >
> > > Add checks for the return value of memory allocation functions
> > > and return an error in case of failure. Update the callers to
> > > handle the error properly.
> > >
> > > Signed-off-by: Wander Lairson Costa <wander@xxxxxxxxxx>
> > > ---
> > > tools/tracing/rtla/src/actions.c | 26 +++++++++++++++++++++++---
> > > tools/tracing/rtla/src/actions.h | 2 +-
> > > tools/tracing/rtla/src/timerlat_hist.c | 7 +++++--
> > > tools/tracing/rtla/src/timerlat_top.c | 7 +++++--
> > > 4 files changed, 34 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/actions.c
> > > index 8945aee58d511..01648a1425c10 100644
> > > --- a/tools/tracing/rtla/src/actions.c
> > > +++ b/tools/tracing/rtla/src/actions.c
> > > @@ -11,11 +11,13 @@
> > > /*
> > > * actions_init - initialize struct actions
> > > */
> > > -void
> > > +int
> > > actions_init(struct actions *self)
> > > {
> > > self->size = action_default_size;
> > > self->list = calloc(self->size, sizeof(struct action));
> > > + if (!self->list)
> > > + return -1;
> >
> > Can you return -ENOMEM?
>
> Does it need to? This is user space not the kernel. Errno is already
> set by calloc() failing.

Ah, indeed! I agree to just return -1.

Reviewed-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>

Thank you,

>
> -- Steve
>


--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>