Messages in this thread Patch in this message | | | Date | Thu, 19 May 2022 16:19:27 -0400 | From | Kent Overstreet <> | Subject | Re: [PATCH v2 22/28] Input/joystick/analog: Convert from seq_buf -> printbuf |
| |
On Thu, May 19, 2022 at 11:04:27PM +0300, Andy Shevchenko wrote: > 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
This conversion predated my adding external buffers to printbufs - now the patch is more of a direct conversion:
-- >8 -- Subject: [PATCH] Input/joystick/analog: Convert from seq_buf -> printbuf
seq_buf is being deprecated, this converts to printbuf.
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> --- drivers/input/joystick/analog.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c index 3088c5b829..1dde969b29 100644 --- a/drivers/input/joystick/analog.c +++ b/drivers/input/joystick/analog.c @@ -19,7 +19,7 @@ #include <linux/input.h> #include <linux/gameport.h> #include <linux/jiffies.h> -#include <linux/seq_buf.h> +#include <linux/printbuf.h> #include <linux/timex.h> #include <linux/timekeeping.h> @@ -339,24 +339,21 @@ static void analog_calibrate_timer(struct analog_port *port) static void analog_name(struct analog *analog) { - struct seq_buf s; + struct printbuf buf = PRINTBUF_EXTERN(analog->name, sizeof(analog->name)); - seq_buf_init(&s, analog->name, sizeof(analog->name)); - seq_buf_printf(&s, "Analog %d-axis %d-button", - hweight8(analog->mask & ANALOG_AXES_STD), - hweight8(analog->mask & ANALOG_BTNS_STD) + !!(analog->mask & ANALOG_BTNS_CHF) * 2 + - hweight16(analog->mask & ANALOG_BTNS_GAMEPAD) + !!(analog->mask & ANALOG_HBTN_CHF) * 4); + pr_buf(&buf, "Analog %d-axis %d-button", + hweight8(analog->mask & ANALOG_AXES_STD), + hweight8(analog->mask & ANALOG_BTNS_STD) + !!(analog->mask & ANALOG_BTNS_CHF) * 2 + + hweight16(analog->mask & ANALOG_BTNS_GAMEPAD) + !!(analog->mask & ANALOG_HBTN_CHF) * 4); if (analog->mask & ANALOG_HATS_ALL) - seq_buf_printf(&s, " %d-hat", - hweight16(analog->mask & ANALOG_HATS_ALL)); - + pr_buf(&buf, " %d-hat", hweight16(analog->mask & ANALOG_HATS_ALL)); if (analog->mask & ANALOG_HAT_FCS) - seq_buf_printf(&s, " FCS"); + pr_buf(&buf, " FCS"); if (analog->mask & ANALOG_ANY_CHF) - seq_buf_printf(&s, (analog->mask & ANALOG_SAITEK) ? " Saitek" : " CHF"); + pr_buf(&buf, (analog->mask & ANALOG_SAITEK) ? " Saitek" : " CHF"); - seq_buf_printf(&s, (analog->mask & ANALOG_GAMEPAD) ? " gamepad" : " joystick"); + pr_buf(&buf, (analog->mask & ANALOG_GAMEPAD) ? " gamepad" : " joystick"); } /* -- 2.36.0
| |