diff options
author | Nathan Lynch <nathanl@linux.ibm.com> | 2024-01-16 08:09:25 -0600 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-01-09 13:32:05 +0100 |
commit | c3b5a7d6a13baa7e5d6deadb929da20809b345e8 (patch) | |
tree | 4e68325ae19922732ad3367ccd50d45454744c7c | |
parent | f2b94ee08ec66c5b1cb13e6289ee3bbef35c1cdb (diff) | |
download | linux-c3b5a7d6a13baa7e5d6deadb929da20809b345e8.tar.gz linux-c3b5a7d6a13baa7e5d6deadb929da20809b345e8.tar.bz2 linux-c3b5a7d6a13baa7e5d6deadb929da20809b345e8.zip |
seq_buf: Make DECLARE_SEQ_BUF() usable
[ Upstream commit 7a8e9cdf9405819105ae7405cd91e482bf574b01 ]
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/20240116-declare-seq-buf-fix-v1-1-915db4692f32@linux.ibm.com
Cc: stable@vger.kernel.org
Acked-by: Kees Cook <keescook@chromium.org>
Fixes: dcc4e5728eea ("seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_str()")
Signed-off-by: Nathan Lynch <nathanl@linux.ibm.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | include/linux/seq_buf.h | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h index d9db59f420a4..468d8c5eef4a 100644 --- a/include/linux/seq_buf.h +++ b/include/linux/seq_buf.h @@ -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, \ } |