Re: [PATCH v5 06/21] perf arm-spe: Refactor printing string to buffer

From: Leo Yan
Date: Thu Oct 29 2020 - 07:06:17 EST


On Thu, Oct 29, 2020 at 10:54:37AM +0000, André Przywara wrote:
> On 29/10/2020 10:51, Leo Yan wrote:
> > Hi Andre,
> >
> > On Thu, Oct 29, 2020 at 10:23:39AM +0000, Andr� Przywara wrote:
> >
> > [...]
> >
> >>> +static int arm_spe_pkt_snprintf(int *err, char **buf_p, size_t *blen,
> >>> + const char *fmt, ...)
> >>> +{
> >>> + va_list ap;
> >>> + int ret;
> >>> +
> >>> + va_start(ap, fmt);
> >>> + ret = vsnprintf(*buf_p, *blen, fmt, ap);
> >>> + va_end(ap);
> >>> +
> >>> + if (ret < 0) {
> >>> + if (err && !*err)
> >>> + *err = ret;
> >>> + } else {
> >>> + *buf_p += ret;
> >>> + *blen -= ret;
> >>> + }
> >>> +
> >>> + return ret;
> >>> +}
> >>
> >> So this now implements the old behaviour of ignoring previous errors, in
> >> all cases, since we don't check for errors and bail out in the callers.
> >>
> >> If you simply check for validity of err and for it being 0 before
> >> proceeding with the va_start() above, this should be fixed.
> >
> > I think you are suggesting below code, could you take a look for it
> > before I proceed to respin new patch?>
> > static int arm_spe_pkt_snprintf(int *err, char **buf_p, size_t *blen,
> > const char *fmt, ...)
> > {
> > va_list ap;
> > int ret;
> >
> > /* Bail out if any error occurred */
> > if (err && *err)
> > return *err;
> >
> > va_start(ap, fmt);
> > ret = vsnprintf(*buf_p, *blen, fmt, ap);
> > va_end(ap);
> >
> > if (ret < 0) {
> > if (err && !*err)
> > *err = ret;
> > } else {
> > *buf_p += ret;
> > *blen -= ret;
> > }
> >
> > return ret;
> > }
>
> Yes, this is what I had in mind.

Thanks for confirmation, Andre.

Leo