[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAM9d7cjJuLdBtN_2it88v4VAmVZ5sSzcpDX-eU9A+hiyO3izaA@mail.gmail.com>
Date: Tue, 24 Aug 2021 12:27:13 -0700
From: Namhyung Kim <namhyung@...nel.org>
To: Riccardo Mancini <rickyman7@...il.com>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>,
Ian Rogers <irogers@...gle.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Mark Rutland <mark.rutland@....com>,
Jiri Olsa <jolsa@...hat.com>,
linux-kernel <linux-kernel@...r.kernel.org>,
linux-perf-users <linux-perf-users@...r.kernel.org>,
Alexey Bayduraev <alexey.v.bayduraev@...ux.intel.com>
Subject: Re: [RFC PATCH v3 06/15] perf workqueue: introduce workqueue struct
Hi Riccardo,
On Fri, Aug 20, 2021 at 3:54 AM Riccardo Mancini <rickyman7@...il.com> wrote:
> +/**
> + * workqueue_strerror - print message regarding lastest error in @wq
> + *
> + * Buffer size should be at least WORKQUEUE_STRERR_BUFSIZE bytes.
> + */
> +int workqueue_strerror(struct workqueue_struct *wq, int err, char *buf, size_t size)
> +{
> + int ret;
> + char sbuf[THREADPOOL_STRERR_BUFSIZE], *emsg;
> + const char *errno_str;
> +
> + errno_str = workqueue_errno_str[-err-WORKQUEUE_ERROR__OFFSET];
It seems easy to crash with an invalid err argument.
> +
> + switch (err) {
> + case -WORKQUEUE_ERROR__POOLNEW:
> + case -WORKQUEUE_ERROR__POOLEXE:
> + case -WORKQUEUE_ERROR__POOLSTOP:
> + case -WORKQUEUE_ERROR__POOLSTARTTHREAD:
> + if (IS_ERR_OR_NULL(wq))
> + return scnprintf(buf, size, "%s: unknown.\n",
> + errno_str);
> +
> + ret = threadpool__strerror(wq->pool, wq->pool_errno, sbuf, sizeof(sbuf));
> + if (ret < 0)
> + return ret;
> + return scnprintf(buf, size, "%s: %s.\n", errno_str, sbuf);
> + case -WORKQUEUE_ERROR__WRITEPIPE:
> + case -WORKQUEUE_ERROR__READPIPE:
> + emsg = str_error_r(errno, sbuf, sizeof(sbuf));
This means the errno should be kept before calling this, right?
> + return scnprintf(buf, size, "%s: %s.\n", errno_str, emsg);
> + case -WORKQUEUE_ERROR__INVALIDMSG:
> + return scnprintf(buf, size, "%s.\n", errno_str);
> + default:
> + emsg = str_error_r(err, sbuf, sizeof(sbuf));
> + return scnprintf(buf, size, "Error: %s", emsg);
Newline at the end?
Thanks,
Namhyung
> + }
> +}
> +
Powered by blists - more mailing lists