Re: [RFC PATCH v3 06/15] perf workqueue: introduce workqueue struct

From: Riccardo Mancini
Date: Tue Aug 31 2021 - 12:13:25 EST


Hi Namhyung,
thanks again for taking your time to review.

On Tue, 2021-08-24 at 12:27 -0700, Namhyung Kim wrote:
> Hi Riccardo,
>
> On Fri, Aug 20, 2021 at 3:54 AM Riccardo Mancini <rickyman7@xxxxxxxxx> 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.

Yup, I should add a check in the next version.

>
> > +
> > +       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?

Yeah, I should make sure to preserve it, I think it's done this way in some
other functions.
Otherwise, I can save it in a struct attribute, which is maybe simpler.

>
> > +               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?

Forgot it, thanks!

Riccardo

>
> Thanks,
> Namhyung
>
>
> > +       }
> > +}
> > +