[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75VfEo644UcOr2YWS3usBBOtxGVciaL4j8fjtomk69x=+3g@mail.gmail.com>
Date: Mon, 31 Aug 2015 21:47:19 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Ingo Molnar <mingo@...hat.com>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Arnaldo Carvalho de Melo <acme@...radead.org>,
Vince Weaver <vince@...ter.net>,
Stephane Eranian <eranian@...gle.com>,
Johannes Berg <johannes@...solutions.net>
Subject: Re: [PATCH v2 1/6] perf: Introduce extended syscall error reporting
On Mon, Aug 24, 2015 at 5:32 PM, Alexander Shishkin
<alexander.shishkin@...ux.intel.com> wrote:
One small comment below.
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -49,6 +49,79 @@
>
> #include <asm/irq_regs.h>
>
> +static bool extended_reporting_enabled(struct perf_event_attr *attr)
> +{
> + if (attr->size >= PERF_ATTR_SIZE_VER6 &&
> + attr->perf_err_size > 0)
> + return true;
> +
> + return false;
> +}
> +
> +/*
> + * Provide a JSON formatted error report to the user if they asked for it.
> + */
> +static void perf_error_report_site(struct perf_event_attr *attr,
> + const struct perf_err_site *site)
> +{
> + unsigned long len;
> + char *buffer;
> +
> + if (!site || !extended_reporting_enabled(attr))
> + return;
> +
> + /* in case of nested perf_err()s, which you shouldn't really do */
> + while (site->code <= -PERF_ERRNO)
> + site = perf_errno_to_site(site->code);
> +
> + buffer = kasprintf(GFP_KERNEL,
> + "{\n"
> + "\t\"code\": %d,\n"
> + "\t\"module\": \"%s\",\n"
> + "\t\"message\": \"%s\"\n"
> + "}\n",
> + site->code, site->owner, site->message
> + );
> + if (!buffer)
> + return;
> +
> + /* trim the buffer to the supplied boundary */
> + len = strlen(buffer);
> + if (len >= attr->perf_err_size) {
> + len = attr->perf_err_size - 1;
> + buffer[len] = 0;
> + }
len = strnlen(buffer, attr->perf_err_size);
buffer[len] = 0;
And perhaps perf_err_size has to be length (perf_err_len) ?
> +
> + if (copy_to_user((void __user *)attr->perf_err, buffer, len + 1)) {
> + /* if we failed to copy once, don't bother later */
> + attr->perf_err_size = 0;
Kaboom next time on buffer[-1] = 0; since len >= 0?
> + }
> +
> + kfree(buffer);
> +}
--
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists