From dc7f600a24e263bba4a69d7c94ab9c0bda9bca02 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 24 May 2011 11:37:06 -0400 Subject: [PATCH] Handle refcount of modules having dynamically alloc event description Signed-off-by: Mathieu Desnoyers --- ltt-events.h | 1 + ltt-probes.c | 9 ++------- probes/lttng-events.h | 1 + probes/lttng-ftrace.c | 1 + probes/lttng-kprobes.c | 1 + 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ltt-events.h b/ltt-events.h index 6cc37531..9baf660d 100644 --- a/ltt-events.h +++ b/ltt-events.h @@ -139,6 +139,7 @@ struct lttng_event_desc { const struct lttng_event_ctx *ctx; /* context */ const struct lttng_event_field *fields; /* event payload */ unsigned int nr_fields; + struct module *owner; }; struct lttng_probe_desc { diff --git a/ltt-probes.c b/ltt-probes.c index ad7f7c2b..0efc23c5 100644 --- a/ltt-probes.c +++ b/ltt-probes.c @@ -30,11 +30,6 @@ const struct lttng_event_desc *find_event(const char *name) return NULL; } -/* - * TODO: registration of probe descriptions in dynamically allocated memory (not - * directly in a module memory) will require some care for refcounting: it's - * currently done by just refcounting the module in event_get/put. - */ int ltt_probe_register(struct lttng_probe_desc *desc) { int ret = 0; @@ -76,7 +71,7 @@ const struct lttng_event_desc *ltt_event_get(const char *name) mutex_unlock(&probe_mutex); if (!event) return NULL; - ret = try_module_get(__module_text_address((unsigned long) event)); + ret = try_module_get(event->owner); WARN_ON_ONCE(!ret); return event; } @@ -84,6 +79,6 @@ EXPORT_SYMBOL_GPL(ltt_event_get); void ltt_event_put(const struct lttng_event_desc *event) { - module_put(__module_text_address((unsigned long) event)); + module_put(event->owner); } EXPORT_SYMBOL_GPL(ltt_event_put); diff --git a/probes/lttng-events.h b/probes/lttng-events.h index 9aaf1573..beedb22b 100644 --- a/probes/lttng-events.h +++ b/probes/lttng-events.h @@ -195,6 +195,7 @@ static void __event_probe__##_name(void *__data, _proto); .name = #_name, \ .probe_callback = (void *) &__event_probe__##_template,\ .nr_fields = ARRAY_SIZE(__event_fields___##_template), \ + .owner = THIS_MODULE, \ }, #define TP_ID1(_token, _system) _token##_system diff --git a/probes/lttng-ftrace.c b/probes/lttng-ftrace.c index 5b4cf2e7..c866876e 100644 --- a/probes/lttng-ftrace.c +++ b/probes/lttng-ftrace.c @@ -92,6 +92,7 @@ int lttng_create_ftrace_event(const char *name, struct ltt_event *event) fields[1].type.u.basic.integer.base = 16; fields[1].type.u.basic.integer.encoding = lttng_encode_none; + desc->owner = THIS_MODULE; event->desc = desc; return 0; diff --git a/probes/lttng-kprobes.c b/probes/lttng-kprobes.c index 65c1d3ba..650144cb 100644 --- a/probes/lttng-kprobes.c +++ b/probes/lttng-kprobes.c @@ -71,6 +71,7 @@ int lttng_create_kprobe_event(const char *name, struct ltt_event *event) field->type.u.basic.integer.reverse_byte_order = 0; field->type.u.basic.integer.base = 16; field->type.u.basic.integer.encoding = lttng_encode_none; + desc->owner = THIS_MODULE; event->desc = desc; return 0; -- 2.34.1