#include <linux/slab.h>
#include <linux/jiffies.h>
#include <linux/utsname.h>
+#include <linux/err.h>
#include "wrapper/uuid.h"
#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
#include "wrapper/random.h"
int ret;
mutex_lock(&sessions_mutex);
- if (chan->free_event_id == -1U)
+ if (chan->free_event_id == -1U) {
+ event = ERR_PTR(-EMFILE);
goto full;
+ }
/*
* This is O(n^2) (for each event, the loop is called at event
* creation). Might require a hash if we have lots of events.
*/
- list_for_each_entry(event, &chan->session->events, list)
- if (!strcmp(event->desc->name, event_param->name))
+ list_for_each_entry(event, &chan->session->events, list) {
+ if (!strcmp(event->desc->name, event_param->name)) {
+ event = ERR_PTR(-EEXIST);
goto exist;
+ }
+ }
event = kmem_cache_zalloc(event_cache, GFP_KERNEL);
- if (!event)
+ if (!event) {
+ event = ERR_PTR(-ENOMEM);
goto cache_error;
+ }
event->chan = chan;
event->filter = filter;
event->id = chan->free_event_id++;
switch (event_param->instrumentation) {
case LTTNG_KERNEL_TRACEPOINT:
event->desc = lttng_event_get(event_param->name);
- if (!event->desc)
+ if (!event->desc) {
+ event = ERR_PTR(-ENOENT);
goto register_error;
+ }
ret = kabi_2635_tracepoint_probe_register(event_param->name,
event->desc->probe_callback,
event);
- if (ret)
+ if (ret) {
+ event = ERR_PTR(-EINVAL);
goto register_error;
+ }
break;
case LTTNG_KERNEL_KPROBE:
ret = lttng_kprobes_register(event_param->name,
event_param->u.kprobe.offset,
event_param->u.kprobe.addr,
event);
- if (ret)
+ if (ret) {
+ event = ERR_PTR(-EINVAL);
goto register_error;
+ }
ret = try_module_get(event->desc->owner);
WARN_ON_ONCE(!ret);
break;
/* kretprobe defines 2 events */
event_return =
kmem_cache_zalloc(event_cache, GFP_KERNEL);
- if (!event_return)
+ if (!event_return) {
+ event = ERR_PTR(-ENOMEM);
goto register_error;
+ }
event_return->chan = chan;
event_return->filter = filter;
event_return->id = chan->free_event_id++;
event, event_return);
if (ret) {
kmem_cache_free(event_cache, event_return);
+ event = ERR_PTR(-EINVAL);
goto register_error;
}
/* Take 2 refs on the module: one per event. */
WARN_ON_ONCE(!ret);
ret = _lttng_event_metadata_statedump(chan->session, chan,
event_return);
+ WARN_ON_ONCE(ret > 0);
if (ret) {
kmem_cache_free(event_cache, event_return);
module_put(event->desc->owner);
module_put(event->desc->owner);
+ event = ERR_PTR(ret);
goto statedump_error;
}
list_add(&event_return->list, &chan->session->events);
ret = lttng_ftrace_register(event_param->name,
event_param->u.ftrace.symbol_name,
event);
- if (ret)
+ if (ret) {
+ event = ERR_PTR(ret);
goto register_error;
+ }
ret = try_module_get(event->desc->owner);
WARN_ON_ONCE(!ret);
break;
case LTTNG_KERNEL_NOOP:
event->desc = internal_desc;
- if (!event->desc)
+ if (!event->desc) {
+ event = ERR_PTR(-EINVAL);
goto register_error;
+ }
break;
default:
WARN_ON_ONCE(1);
+ event = ERR_PTR(-EINVAL);
goto register_error;
}
ret = _lttng_event_metadata_statedump(chan->session, chan, event);
- if (ret)
+ WARN_ON_ONCE(ret > 0);
+ if (ret) {
+ event = ERR_PTR(ret);
goto statedump_error;
+ }
list_add(&event->list, &chan->session->events);
mutex_unlock(&sessions_mutex);
return event;
exist:
full:
mutex_unlock(&sessions_mutex);
- return NULL;
+ return event;
}
/*
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/compat.h>
+#include <linux/err.h>
#include <asm/ptrace.h>
#include <asm/syscall.h>
ev.instrumentation = LTTNG_KERNEL_NOOP;
chan_table[i] = lttng_event_create(chan, &ev, filter,
desc);
- if (!chan_table[i]) {
+ WARN_ON_ONCE(!chan_table[i]);
+ if (IS_ERR(chan_table[i])) {
/*
* If something goes wrong in event registration
* after the first one, we have no choice but to
* leave the previous events in there, until
* deleted by session teardown.
*/
- return -EINVAL;
+ return PTR_ERR(chan_table[i]);
}
}
return 0;
ev.instrumentation = LTTNG_KERNEL_NOOP;
chan->sc_unknown = lttng_event_create(chan, &ev, filter,
desc);
- if (!chan->sc_unknown) {
- return -EINVAL;
+ WARN_ON_ONCE(!chan->sc_unknown);
+ if (IS_ERR(chan->sc_unknown)) {
+ return PTR_ERR(chan->sc_unknown);
}
}
ev.instrumentation = LTTNG_KERNEL_NOOP;
chan->sc_compat_unknown = lttng_event_create(chan, &ev, filter,
desc);
- if (!chan->sc_compat_unknown) {
- return -EINVAL;
+ WARN_ON_ONCE(!chan->sc_unknown);
+ if (IS_ERR(chan->sc_compat_unknown)) {
+ return PTR_ERR(chan->sc_compat_unknown);
}
}
ev.instrumentation = LTTNG_KERNEL_NOOP;
chan->sc_exit = lttng_event_create(chan, &ev, filter,
desc);
- if (!chan->sc_exit) {
- return -EINVAL;
+ WARN_ON_ONCE(!chan->sc_exit);
+ if (IS_ERR(chan->sc_exit)) {
+ return PTR_ERR(chan->sc_exit);
}
}