History

tracing: Add helper function trace_create_new_event() to remove duplicate code

Both __trace_add_new_event() and __trace_early_add_new_event() do basically the same thing, except that __trace_add_new_event() does a little more. Instead of having duplicate code between the two functions, add a helper function trace_create_new_event() that both can use. This will help against having bugs fixed in one function but not the other.

Steven Rostedt (Red Hat) committed 13 years ago

Commit da511bf1 parent 1cf4c071 file · +20 −12Browse files

Showing the changes to kernel/trace (1 of 1 file). Show all

Unified · Split

kernel/trace/trace_events.c+20−12
@@ -1529,6 +1529,24 @@ __register_event(struct ftrace_event_call *call, struct module *mod) · 1528 unmodified lines
15291529 return 0;
15301530 }
15311531
1532+static struct ftrace_event_file *
1533+trace_create_new_event(struct ftrace_event_call *call,
1534+ struct trace_array *tr)
1535+{
1536+ struct ftrace_event_file *file;
1537+
1538+ file = kmem_cache_alloc(file_cachep, GFP_TRACE);
1539+ if (!file)
1540+ return NULL;
1541+
1542+ file->event_call = call;
1543+ file->tr = tr;
1544+ atomic_set(&file->sm_ref, 0);
1545+ list_add(&file->list, &tr->events);
1546+
1547+ return file;
1548+}
1549+
15321550 /* Add an event to a trace directory */
15331551 static int
15341552 __trace_add_new_event(struct ftrace_event_call *call,
@@ -1540,15 +1558,10 @@ __trace_add_new_event(struct ftrace_event_call *call, · 5 unmodified lines
15401558 {
15411559 struct ftrace_event_file *file;
15421560
1543− file = kmem_cache_alloc(file_cachep, GFP_TRACE);
1561+ file = trace_create_new_event(call, tr);
15441562 if (!file)
15451563 return -ENOMEM;
15461564
1547− file->event_call = call;
1548− file->tr = tr;
1549− atomic_set(&file->sm_ref, 0);
1550− list_add(&file->list, &tr->events);
1551−
15521565 return event_create_dir(tr->event_dir, file, id, enable, filter, format);
15531566 }
15541567
@@ -1563,15 +1576,10 @@ __trace_early_add_new_event(struct ftrace_event_call *call, · 8 unmodified lines
15631576 {
15641577 struct ftrace_event_file *file;
15651578
1566− file = kmem_cache_alloc(file_cachep, GFP_TRACE);
1579+ file = trace_create_new_event(call, tr);
15671580 if (!file)
15681581 return -ENOMEM;
15691582
1570− file->event_call = call;
1571− file->tr = tr;
1572− atomic_set(&file->sm_ref, 0);
1573− list_add(&file->list, &tr->events);
1574−
15751583 return 0;
15761584 }
15771585