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, Tom Zanussi wrote:
    > @@ -19,6 +19,34 @@
    >
    > 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);

    Field was not allocated with kzalloc, if we failed to allocate name, then
    type is unknown, and kfree(field->type) may corrupt the system.

    What I would do is:

    field = kzalloc(...);
    if (!field)
    return -ENOMEM;

    And then we could also get rid of the if (field) check in err.


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

    -- Steve


    \
     
     \ /
      Last update: 2009-03-23 19:19    [W:0.043 / U:89.564 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site