]> Git Repo - linux.git/commitdiff
seq_buf: Make DECLARE_SEQ_BUF() usable
authorNathan Lynch <[email protected]>
Tue, 16 Jan 2024 14:09:25 +0000 (08:09 -0600)
committerSteven Rostedt (Google) <[email protected]>
Thu, 18 Jan 2024 14:22:02 +0000 (09:22 -0500)
Using the address operator on the array doesn't work:

./include/linux/seq_buf.h:27:27: error: initialization of ‘char *’
  from incompatible pointer type ‘char (*)[128]’
  [-Werror=incompatible-pointer-types]
   27 |                 .buffer = &__ ## NAME ## _buffer,       \
      |                           ^

Apart from fixing that, we can improve DECLARE_SEQ_BUF() by using a
compound literal to define the buffer array without attaching a name
to it. This makes the macro a single statement, allowing constructs
such as:

  static DECLARE_SEQ_BUF(my_seq_buf, MYSB_SIZE);

to work as intended.

Link: https://lkml.kernel.org/r/[email protected]
Cc: [email protected]
Acked-by: Kees Cook <[email protected]>
Fixes: dcc4e5728eea ("seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_str()")
Signed-off-by: Nathan Lynch <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
include/linux/seq_buf.h

index 5fb1f12c33f90232e774fa2ff5988023277c55f4..c44f4b47b945306318d8ed164c498abfe2512a10 100644 (file)
@@ -22,9 +22,8 @@ struct seq_buf {
 };
 
 #define DECLARE_SEQ_BUF(NAME, SIZE)                    \
-       char __ ## NAME ## _buffer[SIZE] = "";          \
        struct seq_buf NAME = {                         \
-               .buffer = &__ ## NAME ## _buffer,       \
+               .buffer = (char[SIZE]) { 0 },           \
                .size = SIZE,                           \
        }
 
This page took 0.048915 seconds and 4 git commands to generate.