Re: [PATCH v2 22/28] Input/joystick/analog: Convert from seq_buf -> printbuf
From: Andy Shevchenko
Date: Thu May 19 2022 - 16:05:31 EST
On Thu, May 19, 2022 at 01:24:15PM -0400, Kent Overstreet wrote:
> seq_buf is being deprecated, this converts to printbuf which is similar
> but heap allocates the string buffer.
>
> This means we have to consider memory allocation context & failure: Here
> we're in device initialization so GFP_KERNEL should be fine, and also as
> we're in device initialization returning -ENOMEM is fine.
...
> + int ret = 0;
Redundant assignment.
...
> - seq_buf_printf(&s, " %d-hat",
> - hweight16(analog->mask & ANALOG_HATS_ALL));
> + pr_buf(&buf, " %d-hat",
> + hweight16(analog->mask & ANALOG_HATS_ALL));
Now you may put it on one line here and in similar cases.
...
> + ret = buf.allocation_failure ? -ENOMEM : 0;
> + if (!ret)
> + strlcpy(analog->name, buf.buf, sizeof(analog->name));
> + printbuf_exit(&buf);
> + return ret;
Looks like anti-pattern. On top a bit twisted error code manipulation before
checking for error codes, but what about
static int printbuf_export(*buf, *out, size)
{
...
}
ret = printbuf_export(&buf, analog->name, sizeof(analog->name));
printbuf_exit(&buf);
return ret;
?
--
With Best Regards,
Andy Shevchenko