Re: [PATCH 3/4] tracing/profile: Add filter support

From: AmÃrico Wang
Date: Thu Oct 15 2009 - 05:49:38 EST


On Thu, Oct 15, 2009 at 11:21 AM, Li Zefan <lizf@xxxxxxxxxxxxxx> wrote:
> - Add an ioctl to allocate a filter for a perf event.
>
> - Free the filter when the associated perf event is to be freed.
>
> - Do the filtering in perf_swevent_match().
>
> Signed-off-by: Li Zefan <lizf@xxxxxxxxxxxxxx>

{snip}

> +int ftrace_profile_set_filter(struct perf_event *event, int event_id,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â char *filter_str)
> +{
> + Â Â Â int err;
> + Â Â Â struct event_filter *filter;
> + Â Â Â struct filter_parse_state *ps;
> + Â Â Â struct ftrace_event_call *call = NULL;
> +
> + Â Â Â mutex_lock(&event_mutex);
> +
> + Â Â Â list_for_each_entry(call, &ftrace_events, list) {
> + Â Â Â Â Â Â Â if (call->id == event_id)
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â }
> + Â Â Â if (!call)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â if (event->filter)
> + Â Â Â Â Â Â Â return -EEXIST;
> +
> + Â Â Â filter = __alloc_preds();
> + Â Â Â if (IS_ERR(filter))
> + Â Â Â Â Â Â Â return PTR_ERR(filter);


Just return will leave &event_mutex locked...

Am I missing something here?

> +
> + Â Â Â err = -ENOMEM;
> + Â Â Â ps = kzalloc(sizeof(*ps), GFP_KERNEL);
> + Â Â Â if (!ps)
> + Â Â Â Â Â Â Â goto free_preds;
> +
> + Â Â Â parse_init(ps, filter_ops, filter_str);
> + Â Â Â err = filter_parse(ps);
> + Â Â Â if (err)
> + Â Â Â Â Â Â Â goto free_ps;
> +
> + Â Â Â err = replace_preds(call, filter, ps, filter_str, false);
> + Â Â Â if (!err)
> + Â Â Â Â Â Â Â event->filter = filter;
> +
> +free_ps:
> + Â Â Â filter_opstack_clear(ps);
> + Â Â Â postfix_clear(ps);
> + Â Â Â kfree(ps);
> +
> +free_preds:
> + Â Â Â if (err)
> + Â Â Â Â Â Â Â __free_preds(filter);
> +
> + Â Â Â mutex_unlock(&event_mutex);
> +
> + Â Â Â return err;
> +}
> +
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/