From: Nathan Lynch via B4 Relay <devnull+nathanl.linux.ibm.com@kernel.org>
To: "Steven Rostedt (Google)" <rostedt@goodmis.org>,
Kees Cook <keescook@chromium.org>
Cc: linux-kernel@vger.kernel.org, Nathan Lynch <nathanl@linux.ibm.com>
Subject: [PATCH] seq_buf: make DECLARE_SEQ_BUF() usable
Date: Tue, 16 Jan 2024 08:09:25 -0600 [thread overview]
Message-ID: <20240116-declare-seq-buf-fix-v1-1-915db4692f32@linux.ibm.com> (raw)
From: Nathan Lynch <nathanl@linux.ibm.com>
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.
Signed-off-by: Nathan Lynch <nathanl@linux.ibm.com>
Fixes: dcc4e5728eea ("seq_buf: Introduce DECLARE_SEQ_BUF and seq_buf_str()")
---
include/linux/seq_buf.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
index 5fb1f12c33f9..c44f4b47b945 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, \
}
---
base-commit: 70d201a40823acba23899342d62bc2644051ad2e
change-id: 20240112-declare-seq-buf-fix-9803b7e679bc
Best regards,
--
Nathan Lynch <nathanl@linux.ibm.com>
next reply other threads:[~2024-01-16 14:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-16 14:09 Nathan Lynch via B4 Relay [this message]
2024-01-16 19:40 ` [PATCH] seq_buf: make DECLARE_SEQ_BUF() usable Christophe JAILLET
2024-01-16 20:09 ` Steven Rostedt
2024-01-17 14:32 ` Steven Rostedt
2024-01-17 20:29 ` Kees Cook
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240116-declare-seq-buf-fix-v1-1-915db4692f32@linux.ibm.com \
--to=devnull+nathanl.linux.ibm.com@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathanl@linux.ibm.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).