Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1221707 > unrolled thread
| Started by | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| First post | 2015-09-09 23:00 +0200 |
| Last post | 2015-09-15 04:40 +0200 |
| Articles | 9 — 4 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH 4/5] perf tools: Propagate error info from tp_format Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-09 23:00 +0200
Re: [PATCH 4/5] perf tools: Propagate error info from tp_format Jiri Olsa <jolsa@redhat.com> - 2015-09-10 10:30 +0200
Re: [PATCH 4/5] perf tools: Propagate error info from tp_format Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-10 16:20 +0200
Re: [PATCH 4/5] perf tools: Propagate error info from tp_format Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 23:00 +0200
Re: [PATCH 4/5] perf tools: Propagate error info from tp_format Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-09-14 23:10 +0200
Re: [PATCH 4/5] perf tools: Propagate error info from tp_format Raphaël Beamonte <raphael.beamonte@gmail.com> - 2015-09-14 23:10 +0200
Re: [PATCH 4/5] perf tools: Propagate error info from tp_format Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com> - 2015-09-14 23:40 +0200
Re: [PATCH 4/5] perf tools: Propagate error info from tp_format Raphaël Beamonte <raphael.beamonte@gmail.com> - 2015-09-15 00:10 +0200
Re: [PATCH 4/5] perf tools: Propagate error info from tp_format Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com> - 2015-09-15 04:40 +0200
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2015-09-09 23:00 +0200 |
| Subject | Re: [PATCH 4/5] perf tools: Propagate error info from tp_format |
| Message-ID | <q6UDg-5Q3-9@gated-at.bofh.it> |
Em Mon, Sep 07, 2015 at 10:38:06AM +0200, Jiri Olsa escreveu:
> Propagate error info from tp_format via ERR_PTR to get
> it all the way down to the parse-event.c tracepoint adding
> routines. Following functions now return pointer with
> encoded error:
> - tp_format
> - trace_event__tp_format
> - perf_evsel__newtp_idx
> - perf_evsel__newtp
>
> This affects several other places in perf, that cannot use
> pointer check anymore, but must utilize the err.h interface,
> when getting error information from above functions list.
Right, so this is tricky and we must be careful, see below...
> Link: http://lkml.kernel.org/n/tip-bzdckgv1zfp2y8up9l7ojt7y@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> tools/perf/builtin-trace.c | 19 +++++++++++--------
> tools/perf/tests/evsel-tp-sched.c | 10 ++++++++--
> tools/perf/tests/openat-syscall-all-cpus.c | 3 ++-
> tools/perf/tests/openat-syscall-tp-fields.c | 3 ++-
> tools/perf/tests/openat-syscall.c | 3 ++-
> tools/perf/util/evlist.c | 3 ++-
> tools/perf/util/evsel.c | 11 +++++++++--
> tools/perf/util/evsel.h | 3 +++
> tools/perf/util/parse-events.c | 6 +++---
> tools/perf/util/trace-event.c | 13 +++++++++++--
> 10 files changed, 53 insertions(+), 21 deletions(-)
>
> diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
> index 215653274102..93b80f12f35e 100644
> --- a/tools/perf/builtin-trace.c
> +++ b/tools/perf/builtin-trace.c
> @@ -38,6 +38,7 @@
> #include <stdlib.h>
> #include <sys/mman.h>
> #include <linux/futex.h>
> +#include <linux/err.h>
>
> /* For older distros: */
> #ifndef MAP_STACK
> @@ -245,13 +246,14 @@ static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, void
> struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction);
>
> /* older kernel (e.g., RHEL6) use syscalls:{enter,exit} */
> - if (evsel == NULL)
> + if (IS_ERR(evsel))
> evsel = perf_evsel__newtp("syscalls", direction);
>
> - if (evsel) {
> - if (perf_evsel__init_syscall_tp(evsel, handler))
> - goto out_delete;
> - }
> + if (IS_ERR(evsel))
> + return NULL;
> +
> + if (perf_evsel__init_syscall_tp(evsel, handler))
> + goto out_delete;
This kind of stuff is ok, as evsel is a local variable and you kept the
interface for perf_evsel__syscall_newtp(), i.e. it returns NULL if a new
evsel can't be instantiated.
Ok, but that is a different interface than the one used by
perf_evsel__newtp(), that also instantiates a new evsel.
So when one thinks about "foo__new()" we now need to check which one of
the two interfaces it uses, if err.h or if the old NULL based failure
reporting one.
Double tricky if it is foo__new() and foo__new_variant(), as
perf_evsel__syscall_newtp() and perf_evsel__newtp(), i.e. both will
return a "struct perf_evsel" instance, but one using err.h, the other
use NULL.
Ok, you marked the ones using a comment, wonder if we couldn't use
'sparse' somehow here, is it used to check IS_ERR() usage in the kernel?
Ah, but what about this in trace__event_handler() in builtin-trace.c?
if (evsel->tp_format) {
event_format__fprintf(evsel->tp_format, sample->cpu,
sample->raw_data, sample->raw_size,
trace->output);
}
Don't we have to use IS_ERR() here? Ok, no, because if setting up
evsel->tp_format fails, then that evsel will be destroyed and
perf_evsel__newtp() will return ERR_PTR(), so it is ok not no use
ERR_PTR(evsel->tp_format) because it will only be != NULL when it was
successfully set up.
But then, in perf_evsel__newtp_idx if zalloc() fails we will not return
ERR_PTR(), but instead NULL, a-ha, this one seems to be a real bug, no?
/*
* Returns pointer with encoded error via <linux/err.h> interface.
*/
struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx)
{
struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
int err = -ENOMEM;
if (evsel != NULL) {
struct perf_event_attr attr = {
.type = PERF_TYPE_TRACEPOINT,
.sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD),
};
if (asprintf(&evsel->name, "%s:%s", sys, name) < 0)
goto out_free;
evsel->tp_format = trace_event__tp_format(sys, name);
if (IS_ERR(evsel->tp_format)) {
err = PTR_ERR(evsel->tp_format);
goto out_free;
}
event_attr_init(&attr);
attr.config = evsel->tp_format->id;
attr.sample_period = 1;
perf_evsel__init(evsel, &attr, idx);
}
return evsel;
out_free:
zfree(&evsel->name);
free(evsel);
return ERR_PTR(err);
}
>
> return evsel;
>
> @@ -1705,12 +1707,12 @@ static int trace__read_syscall_info(struct trace *trace, int id)
> snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name);
> sc->tp_format = trace_event__tp_format("syscalls", tp_name);
>
> - if (sc->tp_format == NULL && sc->fmt && sc->fmt->alias) {
> + if (IS_ERR(sc->tp_format) && sc->fmt && sc->fmt->alias) {
> snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias);
> sc->tp_format = trace_event__tp_format("syscalls", tp_name);
> }
>
> - if (sc->tp_format == NULL)
> + if (IS_ERR(sc->tp_format))
> return -1;
>
> sc->args = sc->tp_format->format.fields;
> @@ -2390,7 +2392,8 @@ static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
> static bool perf_evlist__add_vfs_getname(struct perf_evlist *evlist)
> {
> struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname");
> - if (evsel == NULL)
> +
> + if (IS_ERR(evsel))
> return false;
>
> if (perf_evsel__field(evsel, "pathname") == NULL) {
> diff --git a/tools/perf/tests/evsel-tp-sched.c b/tools/perf/tests/evsel-tp-sched.c
> index 52162425c969..790e413d9a1f 100644
> --- a/tools/perf/tests/evsel-tp-sched.c
> +++ b/tools/perf/tests/evsel-tp-sched.c
> @@ -1,3 +1,4 @@
> +#include <linux/err.h>
> #include <traceevent/event-parse.h>
> #include "evsel.h"
> #include "tests.h"
> @@ -36,8 +37,8 @@ int test__perf_evsel__tp_sched_test(void)
> struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch");
> int ret = 0;
>
> - if (evsel == NULL) {
> - pr_debug("perf_evsel__new\n");
> + if (IS_ERR(evsel)) {
> + pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
> return -1;
> }
>
> @@ -66,6 +67,11 @@ int test__perf_evsel__tp_sched_test(void)
>
> evsel = perf_evsel__newtp("sched", "sched_wakeup");
>
> + if (IS_ERR(evsel)) {
> + pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
> + return -1;
> + }
> +
> if (perf_evsel__test_field(evsel, "comm", 16, true))
> ret = -1;
>
> diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c
> index 495d8126b722..9e104a2e973d 100644
> --- a/tools/perf/tests/openat-syscall-all-cpus.c
> +++ b/tools/perf/tests/openat-syscall-all-cpus.c
> @@ -1,4 +1,5 @@
> #include <api/fs/fs.h>
> +#include <linux/err.h>
> #include "evsel.h"
> #include "tests.h"
> #include "thread_map.h"
> @@ -31,7 +32,7 @@ int test__openat_syscall_event_on_all_cpus(void)
> CPU_ZERO(&cpu_set);
>
> evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
> - if (evsel == NULL) {
> + if (IS_ERR(evsel)) {
> tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
> pr_err("%s\n", errbuf);
> goto out_thread_map_delete;
> diff --git a/tools/perf/tests/openat-syscall-tp-fields.c b/tools/perf/tests/openat-syscall-tp-fields.c
> index 01a19626c846..473d3869727e 100644
> --- a/tools/perf/tests/openat-syscall-tp-fields.c
> +++ b/tools/perf/tests/openat-syscall-tp-fields.c
> @@ -1,3 +1,4 @@
> +#include <linux/err.h>
> #include "perf.h"
> #include "evlist.h"
> #include "evsel.h"
> @@ -30,7 +31,7 @@ int test__syscall_openat_tp_fields(void)
> }
>
> evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
> - if (evsel == NULL) {
> + if (IS_ERR(evsel)) {
> pr_debug("%s: perf_evsel__newtp\n", __func__);
> goto out_delete_evlist;
> }
> diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-syscall.c
> index 08ac9d94a050..7b1db8306098 100644
> --- a/tools/perf/tests/openat-syscall.c
> +++ b/tools/perf/tests/openat-syscall.c
> @@ -1,4 +1,5 @@
> #include <api/fs/tracing_path.h>
> +#include <linux/err.h>
> #include "thread_map.h"
> #include "evsel.h"
> #include "debug.h"
> @@ -19,7 +20,7 @@ int test__openat_syscall_event(void)
> }
>
> evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
> - if (evsel == NULL) {
> + if (IS_ERR(evsel)) {
> tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
> pr_err("%s\n", errbuf);
> goto out_thread_map_delete;
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index d51a5200c8af..3cb2bf9bd4bd 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -25,6 +25,7 @@
> #include <linux/bitops.h>
> #include <linux/hash.h>
> #include <linux/log2.h>
> +#include <linux/err.h>
>
> static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx);
> static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx);
> @@ -265,7 +266,7 @@ int perf_evlist__add_newtp(struct perf_evlist *evlist,
> {
> struct perf_evsel *evsel = perf_evsel__newtp(sys, name);
>
> - if (evsel == NULL)
> + if (IS_ERR(evsel))
> return -1;
>
> evsel->handler = handler;
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 771ade4d5966..08c20ee4e27d 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -13,6 +13,7 @@
> #include <traceevent/event-parse.h>
> #include <linux/hw_breakpoint.h>
> #include <linux/perf_event.h>
> +#include <linux/err.h>
> #include <sys/resource.h>
> #include "asm/bug.h"
> #include "callchain.h"
> @@ -225,9 +226,13 @@ struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
> return evsel;
> }
>
> +/*
> + * Returns pointer with encoded error via <linux/err.h> interface.
> + */
> struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx)
> {
> struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
> + int err = -ENOMEM;
>
> if (evsel != NULL) {
> struct perf_event_attr attr = {
> @@ -240,8 +245,10 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
> goto out_free;
>
> evsel->tp_format = trace_event__tp_format(sys, name);
> - if (evsel->tp_format == NULL)
> + if (IS_ERR(evsel->tp_format)) {
> + err = PTR_ERR(evsel->tp_format);
> goto out_free;
> + }
>
> event_attr_init(&attr);
> attr.config = evsel->tp_format->id;
> @@ -254,7 +261,7 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
> out_free:
> zfree(&evsel->name);
> free(evsel);
> - return NULL;
> + return ERR_PTR(err);
> }
>
> const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = {
> diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
> index 298e6bbca200..b6e8ff876f17 100644
> --- a/tools/perf/util/evsel.h
> +++ b/tools/perf/util/evsel.h
> @@ -161,6 +161,9 @@ static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
>
> struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);
>
> +/*
> + * Returns pointer with encoded error via <linux/err.h> interface.
> + */
> static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name)
> {
> return perf_evsel__newtp_idx(sys, name, 0);
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 1b284b8ad243..c47831c47220 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -1,4 +1,5 @@
> #include <linux/hw_breakpoint.h>
> +#include <linux/err.h>
> #include "util.h"
> #include "../perf.h"
> #include "evlist.h"
> @@ -393,11 +394,10 @@ static int add_tracepoint(struct list_head *list, int *idx,
> struct perf_evsel *evsel;
>
> evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++);
> - if (!evsel)
> - return -ENOMEM;
> + if (IS_ERR(evsel))
> + return PTR_ERR(evsel);
>
> list_add_tail(&evsel->node, list);
> -
> return 0;
> }
>
> diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
> index 2f4996ab313d..8e3a60e3e15f 100644
> --- a/tools/perf/util/trace-event.c
> +++ b/tools/perf/util/trace-event.c
> @@ -7,6 +7,7 @@
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <linux/kernel.h>
> +#include <linux/err.h>
> #include <traceevent/event-parse.h>
> #include <api/fs/tracing_path.h>
> #include "trace-event.h"
> @@ -66,6 +67,9 @@ void trace_event__cleanup(struct trace_event *t)
> pevent_free(t->pevent);
> }
>
> +/*
> + * Returns pointer with encoded error via <linux/err.h> interface.
> + */
> static struct event_format*
> tp_format(const char *sys, const char *name)
> {
> @@ -74,12 +78,14 @@ tp_format(const char *sys, const char *name)
> char path[PATH_MAX];
> size_t size;
> char *data;
> + int err;
>
> scnprintf(path, PATH_MAX, "%s/%s/%s/format",
> tracing_events_path, sys, name);
>
> - if (filename__read_str(path, &data, &size))
> - return NULL;
> + err = filename__read_str(path, &data, &size);
> + if (err)
> + return ERR_PTR(err);
>
> pevent_parse_format(pevent, &event, data, size, sys);
>
> @@ -87,6 +93,9 @@ tp_format(const char *sys, const char *name)
> return event;
> }
>
> +/*
> + * Returns pointer with encoded error via <linux/err.h> interface.
> + */
> struct event_format*
> trace_event__tp_format(const char *sys, const char *name)
> {
> --
> 2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Jiri Olsa <jolsa@redhat.com> |
|---|---|
| Date | 2015-09-10 10:30 +0200 |
| Message-ID | <q75oZ-4nU-7@gated-at.bofh.it> |
| In reply to | #1221707 |
On Wed, Sep 09, 2015 at 05:58:13PM -0300, Arnaldo Carvalho de Melo wrote:
SNIP
> This kind of stuff is ok, as evsel is a local variable and you kept the
> interface for perf_evsel__syscall_newtp(), i.e. it returns NULL if a new
> evsel can't be instantiated.
>
> Ok, but that is a different interface than the one used by
> perf_evsel__newtp(), that also instantiates a new evsel.
>
> So when one thinks about "foo__new()" we now need to check which one of
> the two interfaces it uses, if err.h or if the old NULL based failure
> reporting one.
>
> Double tricky if it is foo__new() and foo__new_variant(), as
> perf_evsel__syscall_newtp() and perf_evsel__newtp(), i.e. both will
> return a "struct perf_evsel" instance, but one using err.h, the other
> use NULL.
>
> Ok, you marked the ones using a comment, wonder if we couldn't use
> 'sparse' somehow here, is it used to check IS_ERR() usage in the kernel?
hum, not sure.. will check ;-)
at least we could mark related functions with __must_check
to force the return value check
>
> Ah, but what about this in trace__event_handler() in builtin-trace.c?
>
> if (evsel->tp_format) {
> event_format__fprintf(evsel->tp_format, sample->cpu,
> sample->raw_data, sample->raw_size,
> trace->output);
> }
>
>
> Don't we have to use IS_ERR() here? Ok, no, because if setting up
> evsel->tp_format fails, then that evsel will be destroyed and
> perf_evsel__newtp() will return ERR_PTR(), so it is ok not no use
> ERR_PTR(evsel->tp_format) because it will only be != NULL when it was
> successfully set up.
>
> But then, in perf_evsel__newtp_idx if zalloc() fails we will not return
> ERR_PTR(), but instead NULL, a-ha, this one seems to be a real bug, no?
hate those allocations in declarations.. never do any good ;-)
yep, NULL is not an error, so it's real bug, attached patch should fix it
thanks,
jirka
---
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 08c20ee4e27d..162973bec713 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -256,7 +256,7 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
perf_evsel__init(evsel, &attr, idx);
}
- return evsel;
+ return evsel ?: ERR_PTR(err);
out_free:
zfree(&evsel->name);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2015-09-10 16:20 +0200 |
| Message-ID | <q7aRH-3Sb-11@gated-at.bofh.it> |
| In reply to | #1221998 |
Em Thu, Sep 10, 2015 at 10:24:52AM +0200, Jiri Olsa escreveu:
> On Wed, Sep 09, 2015 at 05:58:13PM -0300, Arnaldo Carvalho de Melo wrote:
>
> SNIP
>
> > This kind of stuff is ok, as evsel is a local variable and you kept the
> > interface for perf_evsel__syscall_newtp(), i.e. it returns NULL if a new
> > evsel can't be instantiated.
> >
> > Ok, but that is a different interface than the one used by
> > perf_evsel__newtp(), that also instantiates a new evsel.
> >
> > So when one thinks about "foo__new()" we now need to check which one of
> > the two interfaces it uses, if err.h or if the old NULL based failure
> > reporting one.
> >
> > Double tricky if it is foo__new() and foo__new_variant(), as
> > perf_evsel__syscall_newtp() and perf_evsel__newtp(), i.e. both will
> > return a "struct perf_evsel" instance, but one using err.h, the other
> > use NULL.
> >
> > Ok, you marked the ones using a comment, wonder if we couldn't use
> > 'sparse' somehow here, is it used to check IS_ERR() usage in the kernel?
>
> hum, not sure.. will check ;-)
>
> at least we could mark related functions with __must_check
> to force the return value check
Right, that helps a bit, but not when the test _is already there_,
against NULL.
That is why I thought about sparse, if it was used in the kernel somehow
to check for this, guess either it would notice ERR_PTR using routines
and then auto-mark them for checking if they are being tested using
IS_ERR() or plain NULL, will check, later...
- Arnaldo
> >
> > Ah, but what about this in trace__event_handler() in builtin-trace.c?
> >
> > if (evsel->tp_format) {
> > event_format__fprintf(evsel->tp_format, sample->cpu,
> > sample->raw_data, sample->raw_size,
> > trace->output);
> > }
> >
> >
> > Don't we have to use IS_ERR() here? Ok, no, because if setting up
> > evsel->tp_format fails, then that evsel will be destroyed and
> > perf_evsel__newtp() will return ERR_PTR(), so it is ok not no use
> > ERR_PTR(evsel->tp_format) because it will only be != NULL when it was
> > successfully set up.
> >
> > But then, in perf_evsel__newtp_idx if zalloc() fails we will not return
> > ERR_PTR(), but instead NULL, a-ha, this one seems to be a real bug, no?
>
> hate those allocations in declarations.. never do any good ;-)
>
> yep, NULL is not an error, so it's real bug, attached patch should fix it
>
> thanks,
> jirka
>
>
> ---
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 08c20ee4e27d..162973bec713 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -256,7 +256,7 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
> perf_evsel__init(evsel, &attr, idx);
> }
>
> - return evsel;
> + return evsel ?: ERR_PTR(err);
>
> out_free:
> zfree(&evsel->name);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2015-09-14 23:00 +0200 |
| Message-ID | <q8J10-Ci-19@gated-at.bofh.it> |
| In reply to | #1221998 |
Em Thu, Sep 10, 2015 at 10:24:52AM +0200, Jiri Olsa escreveu:
> On Wed, Sep 09, 2015 at 05:58:13PM -0300, Arnaldo Carvalho de Melo wrote:
>
> SNIP
>
> > This kind of stuff is ok, as evsel is a local variable and you kept the
> > interface for perf_evsel__syscall_newtp(), i.e. it returns NULL if a new
> > evsel can't be instantiated.
> >
> > Ok, but that is a different interface than the one used by
> > perf_evsel__newtp(), that also instantiates a new evsel.
> >
> > So when one thinks about "foo__new()" we now need to check which one of
> > the two interfaces it uses, if err.h or if the old NULL based failure
> > reporting one.
> >
> > Double tricky if it is foo__new() and foo__new_variant(), as
> > perf_evsel__syscall_newtp() and perf_evsel__newtp(), i.e. both will
> > return a "struct perf_evsel" instance, but one using err.h, the other
> > use NULL.
> >
> > Ok, you marked the ones using a comment, wonder if we couldn't use
> > 'sparse' somehow here, is it used to check IS_ERR() usage in the kernel?
>
> hum, not sure.. will check ;-)
>
> at least we could mark related functions with __must_check
> to force the return value check
>
> >
> > Ah, but what about this in trace__event_handler() in builtin-trace.c?
> >
> > if (evsel->tp_format) {
> > event_format__fprintf(evsel->tp_format, sample->cpu,
> > sample->raw_data, sample->raw_size,
> > trace->output);
> > }
> >
> >
> > Don't we have to use IS_ERR() here? Ok, no, because if setting up
> > evsel->tp_format fails, then that evsel will be destroyed and
> > perf_evsel__newtp() will return ERR_PTR(), so it is ok not no use
> > ERR_PTR(evsel->tp_format) because it will only be != NULL when it was
> > successfully set up.
> >
> > But then, in perf_evsel__newtp_idx if zalloc() fails we will not return
> > ERR_PTR(), but instead NULL, a-ha, this one seems to be a real bug, no?
>
> hate those allocations in declarations.. never do any good ;-)
>
> yep, NULL is not an error, so it's real bug, attached patch should fix it
>
> thanks,
> jirka
Ok continuing, found two more problems in this patch, fixed as follows,
merging.
- Arnaldo
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 666b67a4df9d..4bb0c5d2059d 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -65,7 +65,7 @@ int test__basic_mmap(void)
snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]);
evsels[i] = perf_evsel__newtp("syscalls", name);
- if (evsels[i] == NULL) {
+ if (IS_ERR(evsels[i]) == NULL) {
pr_debug("perf_evsel__new\n");
goto out_delete_evlist;
}
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 08c20ee4e27d..6b5d1b509148 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -234,7 +234,9 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
int err = -ENOMEM;
- if (evsel != NULL) {
+ if (evsel == NULL) {
+ goto out_err;
+ } else {
struct perf_event_attr attr = {
.type = PERF_TYPE_TRACEPOINT,
.sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
@@ -261,6 +263,7 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
out_free:
zfree(&evsel->name);
free(evsel);
+out_err:
return ERR_PTR(err);
}
diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
index 8e3a60e3e15f..802bb868d446 100644
--- a/tools/perf/util/trace-event.c
+++ b/tools/perf/util/trace-event.c
@@ -100,7 +100,7 @@ struct event_format*
trace_event__tp_format(const char *sys, const char *name)
{
if (!tevent_initialized && trace_event__init2())
- return NULL;
+ return ERR_PTR(-ENOMEM);
return tp_format(sys, name);
}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2015-09-14 23:10 +0200 |
| Message-ID | <q8JaF-12P-13@gated-at.bofh.it> |
| In reply to | #1224449 |
Em Mon, Sep 14, 2015 at 05:53:03PM -0300, Arnaldo Carvalho de Melo escreveu:
> Ok continuing, found two more problems in this patch, fixed as follows,
> merging.
> - Arnaldo
> +++ b/tools/perf/tests/mmap-basic.c
> @@ -65,7 +65,7 @@ int test__basic_mmap(void)
>
> snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]);
> evsels[i] = perf_evsel__newtp("syscalls", name);
> - if (evsels[i] == NULL) {
> + if (IS_ERR(evsels[i]) == NULL) {
modulo the == NULL ;-)
> pr_debug("perf_evsel__new\n");
> goto out_delete_evlist;
> }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Raphaël Beamonte <raphael.beamonte@gmail.com> |
|---|---|
| Date | 2015-09-14 23:10 +0200 |
| Message-ID | <q8JaF-12P-15@gated-at.bofh.it> |
| In reply to | #1224449 |
2015-09-14 16:53 GMT-04:00 Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>:
> Em Thu, Sep 10, 2015 at 10:24:52AM +0200, Jiri Olsa escreveu:
>> On Wed, Sep 09, 2015 at 05:58:13PM -0300, Arnaldo Carvalho de Melo wrote:
>>
>> SNIP
>>
>> > This kind of stuff is ok, as evsel is a local variable and you kept the
>> > interface for perf_evsel__syscall_newtp(), i.e. it returns NULL if a new
>> > evsel can't be instantiated.
>> >
>> > Ok, but that is a different interface than the one used by
>> > perf_evsel__newtp(), that also instantiates a new evsel.
>> >
>> > So when one thinks about "foo__new()" we now need to check which one of
>> > the two interfaces it uses, if err.h or if the old NULL based failure
>> > reporting one.
>> >
>> > Double tricky if it is foo__new() and foo__new_variant(), as
>> > perf_evsel__syscall_newtp() and perf_evsel__newtp(), i.e. both will
>> > return a "struct perf_evsel" instance, but one using err.h, the other
>> > use NULL.
>> >
>> > Ok, you marked the ones using a comment, wonder if we couldn't use
>> > 'sparse' somehow here, is it used to check IS_ERR() usage in the kernel?
>>
>> hum, not sure.. will check ;-)
>>
>> at least we could mark related functions with __must_check
>> to force the return value check
>>
>> >
>> > Ah, but what about this in trace__event_handler() in builtin-trace.c?
>> >
>> > if (evsel->tp_format) {
>> > event_format__fprintf(evsel->tp_format, sample->cpu,
>> > sample->raw_data, sample->raw_size,
>> > trace->output);
>> > }
>> >
>> >
>> > Don't we have to use IS_ERR() here? Ok, no, because if setting up
>> > evsel->tp_format fails, then that evsel will be destroyed and
>> > perf_evsel__newtp() will return ERR_PTR(), so it is ok not no use
>> > ERR_PTR(evsel->tp_format) because it will only be != NULL when it was
>> > successfully set up.
>> >
>> > But then, in perf_evsel__newtp_idx if zalloc() fails we will not return
>> > ERR_PTR(), but instead NULL, a-ha, this one seems to be a real bug, no?
>>
>> hate those allocations in declarations.. never do any good ;-)
>>
>> yep, NULL is not an error, so it's real bug, attached patch should fix it
>>
>> thanks,
>> jirka
>
>
> Ok continuing, found two more problems in this patch, fixed as follows,
> merging.
>
> - Arnaldo
>
> diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
> index 666b67a4df9d..4bb0c5d2059d 100644
> --- a/tools/perf/tests/mmap-basic.c
> +++ b/tools/perf/tests/mmap-basic.c
> @@ -65,7 +65,7 @@ int test__basic_mmap(void)
>
> snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]);
> evsels[i] = perf_evsel__newtp("syscalls", name);
> - if (evsels[i] == NULL) {
> + if (IS_ERR(evsels[i]) == NULL) {
> pr_debug("perf_evsel__new\n");
> goto out_delete_evlist;
> }
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index 08c20ee4e27d..6b5d1b509148 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -234,7 +234,9 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
> struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
> int err = -ENOMEM;
>
> - if (evsel != NULL) {
> + if (evsel == NULL) {
> + goto out_err;
> + } else {
Is the else really necessary after a goto?
> struct perf_event_attr attr = {
> .type = PERF_TYPE_TRACEPOINT,
> .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
> @@ -261,6 +263,7 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
> out_free:
> zfree(&evsel->name);
> free(evsel);
> +out_err:
> return ERR_PTR(err);
> }
>
> diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
> index 8e3a60e3e15f..802bb868d446 100644
> --- a/tools/perf/util/trace-event.c
> +++ b/tools/perf/util/trace-event.c
> @@ -100,7 +100,7 @@ struct event_format*
> trace_event__tp_format(const char *sys, const char *name)
> {
> if (!tevent_initialized && trace_event__init2())
> - return NULL;
> + return ERR_PTR(-ENOMEM);
>
> return tp_format(sys, name);
> }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com> |
|---|---|
| Date | 2015-09-14 23:40 +0200 |
| Message-ID | <q8JDI-1AN-1@gated-at.bofh.it> |
| In reply to | #1224453 |
Em Mon, Sep 14, 2015 at 04:59:41PM -0400, Raphaël Beamonte escreveu:
> 2015-09-14 16:53 GMT-04:00 Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>:
> > +++ b/tools/perf/util/evsel.c
> > @@ -234,7 +234,9 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
> > struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
> > int err = -ENOMEM;
> >
> > - if (evsel != NULL) {
> > + if (evsel == NULL) {
> > + goto out_err;
> > + } else {
>
> Is the else really necessary after a goto?
Not really, we can remove it and all would be equivalent (the code
with/without should be the same), its just that I wanted to avoid
touching the identation to reduce patch size and since we need o open a
brace to declare that attr variable...
- Arnaldo
> > struct perf_event_attr attr = {
> > .type = PERF_TYPE_TRACEPOINT,
> > .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
> > @@ -261,6 +263,7 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
> > out_free:
> > zfree(&evsel->name);
> > free(evsel);
> > +out_err:
> > return ERR_PTR(err);
> > }
> >
> > diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
> > index 8e3a60e3e15f..802bb868d446 100644
> > --- a/tools/perf/util/trace-event.c
> > +++ b/tools/perf/util/trace-event.c
> > @@ -100,7 +100,7 @@ struct event_format*
> > trace_event__tp_format(const char *sys, const char *name)
> > {
> > if (!tevent_initialized && trace_event__init2())
> > - return NULL;
> > + return ERR_PTR(-ENOMEM);
> >
> > return tp_format(sys, name);
> > }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Raphaël Beamonte <raphael.beamonte@gmail.com> |
|---|---|
| Date | 2015-09-15 00:10 +0200 |
| Message-ID | <q8K6K-2nU-17@gated-at.bofh.it> |
| In reply to | #1224470 |
2015-09-14 17:36 GMT-04:00 Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>:
> Em Mon, Sep 14, 2015 at 04:59:41PM -0400, Raphaël Beamonte escreveu:
>> 2015-09-14 16:53 GMT-04:00 Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>:
>> > +++ b/tools/perf/util/evsel.c
>> > @@ -234,7 +234,9 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
>> > struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
>> > int err = -ENOMEM;
>> >
>> > - if (evsel != NULL) {
>> > + if (evsel == NULL) {
>> > + goto out_err;
>> > + } else {
>>
>> Is the else really necessary after a goto?
>
> Not really, we can remove it and all would be equivalent (the code
> with/without should be the same), its just that I wanted to avoid
> touching the identation to reduce patch size and since we need o open a
> brace to declare that attr variable...
>
> - Arnaldo
Ok. Though, given the content of that function, we could probably
declare attr in the first lines of the function and assign it its
value after the if. But I understand the patch size argument! :o)
On another subject, but on the same lines, shouldn't we use if
(!evsel) instead of if (evsel == NULL)? (kernel code style if I'm not
mistaken) Or is there something that prevents from using it here?
>> > struct perf_event_attr attr = {
>> > .type = PERF_TYPE_TRACEPOINT,
>> > .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
>> > @@ -261,6 +263,7 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
>> > out_free:
>> > zfree(&evsel->name);
>> > free(evsel);
>> > +out_err:
>> > return ERR_PTR(err);
>> > }
>> >
>> > diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
>> > index 8e3a60e3e15f..802bb868d446 100644
>> > --- a/tools/perf/util/trace-event.c
>> > +++ b/tools/perf/util/trace-event.c
>> > @@ -100,7 +100,7 @@ struct event_format*
>> > trace_event__tp_format(const char *sys, const char *name)
>> > {
>> > if (!tevent_initialized && trace_event__init2())
>> > - return NULL;
>> > + return ERR_PTR(-ENOMEM);
>> >
>> > return tp_format(sys, name);
>> > }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com> |
|---|---|
| Date | 2015-09-15 04:40 +0200 |
| Message-ID | <q8Ok2-8ll-1@gated-at.bofh.it> |
| In reply to | #1224493 |
Em Mon, Sep 14, 2015 at 06:05:38PM -0400, Raphaël Beamonte escreveu:
> 2015-09-14 17:36 GMT-04:00 Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>:
> > Em Mon, Sep 14, 2015 at 04:59:41PM -0400, Raphaël Beamonte escreveu:
> >> 2015-09-14 16:53 GMT-04:00 Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>:
> >> > +++ b/tools/perf/util/evsel.c
> >> > @@ -234,7 +234,9 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
> >> > struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
> >> > int err = -ENOMEM;
> >> >
> >> > - if (evsel != NULL) {
> >> > + if (evsel == NULL) {
> >> > + goto out_err;
> >> > + } else {
> >>
> >> Is the else really necessary after a goto?
> >
> > Not really, we can remove it and all would be equivalent (the code
> > with/without should be the same), its just that I wanted to avoid
> > touching the identation to reduce patch size and since we need o open a
> > brace to declare that attr variable...
>
> Ok. Though, given the content of that function, we could probably
> declare attr in the first lines of the function and assign it its
> value after the if. But I understand the patch size argument! :o)
Yeah, in other times I would have cleaned it all up, having that else is
ugly, but review time is more expensive, I think, so we need to reduce
its cost.
Cleaning it up makes it easier to read, but we get the info about when
that particular code was written buried a bit below the reindentation
cset.
Would be nice to have a 'git blame' that would just unwind things like
that :-)
> On another subject, but on the same lines, shouldn't we use if
> (!evsel) instead of if (evsel == NULL)? (kernel code style if I'm not
> mistaken) Or is there something that prevents from using it here?
I'd say both are ok. (evsel) is shorter than (evsel != NULL), but the
later is more expressive, at a glance you know it is a pointer, etc.
- Arnaldo
> >> > struct perf_event_attr attr = {
> >> > .type = PERF_TYPE_TRACEPOINT,
> >> > .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
> >> > @@ -261,6 +263,7 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
> >> > out_free:
> >> > zfree(&evsel->name);
> >> > free(evsel);
> >> > +out_err:
> >> > return ERR_PTR(err);
> >> > }
> >> >
> >> > diff --git a/tools/perf/util/trace-event.c b/tools/perf/util/trace-event.c
> >> > index 8e3a60e3e15f..802bb868d446 100644
> >> > --- a/tools/perf/util/trace-event.c
> >> > +++ b/tools/perf/util/trace-event.c
> >> > @@ -100,7 +100,7 @@ struct event_format*
> >> > trace_event__tp_format(const char *sys, const char *name)
> >> > {
> >> > if (!tevent_initialized && trace_event__init2())
> >> > - return NULL;
> >> > + return ERR_PTR(-ENOMEM);
> >> >
> >> > return tp_format(sys, name);
> >> > }
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web