lkml.org 
[lkml]   [2009]   [Mar]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/4] tracing: add run-time field descriptions for event filtering

On Sun, 22 Mar 2009, Frederic Weisbecker wrote:
> > static DEFINE_MUTEX(event_mutex);
> >
> > +int trace_define_field(struct ftrace_event_call *call, char *type,
> > + char *name, int offset, int size)
> > +{
> > + struct ftrace_event_field *field;
> > +
> > + field = kmalloc(sizeof(*field), GFP_KERNEL);
> > + if (!field)
> > + goto err;
> > + field->name = kstrdup(name, GFP_KERNEL);
> > + if (!field->name)
> > + goto err;
> > + field->type = kstrdup(type, GFP_KERNEL);
> > + if (!field->type)
> > + goto err;
> > + field->offset = offset;
> > + field->size = size;
> > + list_add(&field->link, &call->fields);
> > +
> > + return 0;
> > +err:
> > + if (field) {
> > + kfree(field->name);
> > + kfree(field->type);
>
>
> You need kzalloc to allocate field.
> With kmalloc, field will point to random filled memory
> after a fresh allocation.
>
> Imagine this path:
>
> if (!field->name)
> goto err;
> ...
> err:
> kfree(field->name) <- field->name = NULL, correct
> kfree(field->type) <- field->type = ?
>

Looks like Frederic got to you first ;-)

-- Steve

>
> > + }
> > + kfree(field);
> > + return -ENOMEM;
> > +}
> > +


\
 
 \ /
  Last update: 2009-03-23 19:55    [W:0.080 / U:1.236 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site