* [RFC v1] seq_buf: Add seq_buf_create() to implement DECLARE_SEQ_BUF()
@ 2026-10-28 23:19 Alejandro Colomar
2026-10-29 1:12 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Alejandro Colomar @ 2026-10-28 23:19 UTC (permalink / raw)
To: linux-hardening
Cc: Alejandro Colomar, Steven Rostedt, Nathan Lynch, Kees Cook
[-- Attachment #1: Type: text/plain, Size: 2142 bytes --]
This implements DECLARE_SEQ_BUF() in a way that is independent of the
members of the structure.
This will allow transitioning to a different implementation of seq_buf
which uses pointers instead of sizes, on which I plan to work soon.
The compiler should be able to optimize this out and produce the same
code as before.
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Nathan Lynch <nathanl@linux.ibm.com>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
Hi Steve, Kees,
This is a patch that I could split from the rewrite using pointers, so
we can apply it earlier to reduce the later diff.
I've built a kernel with 'allmodconfig' to check that it's okay.
The reason I need this patch is that we can't calculate the end pointer
of the compound literal without passing it to a function. If you want
me to hold this patch and send it together with the rest of the rewrite,
I can also do that, but I thought this might be useful by itself.
Have a lovely night!
Alex
include/linux/seq_buf.h | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
index 9f2839e73f8a..facc5643c049 100644
--- a/include/linux/seq_buf.h
+++ b/include/linux/seq_buf.h
@@ -25,10 +25,7 @@ struct seq_buf {
};
#define DECLARE_SEQ_BUF(NAME, SIZE) \
- struct seq_buf NAME = { \
- .buffer = (char[SIZE]) { 0 }, \
- .size = SIZE, \
- }
+ struct seq_buf NAME = seq_buf_create((char[SIZE]){0}, SIZE)
static inline void seq_buf_clear(struct seq_buf *s)
{
@@ -45,6 +42,15 @@ seq_buf_init(struct seq_buf *s, char *buf, unsigned int size)
seq_buf_clear(s);
}
+static inline struct seq_buf
+seq_buf_create(char *buf, unsigned int size)
+{
+ struct seq_buf s;
+
+ seq_buf_init(&s, buf, size);
+ return s;
+}
+
/*
* seq_buf have a buffer that might overflow. When this happens
* len is set to be greater than size.
Range-diff against v0:
-: ------------ > 1: 9bda534b33f0 seq_buf: Add seq_buf_create() to implement DECLARE_SEQ_BUF()
--
2.55.0
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [RFC v1] seq_buf: Add seq_buf_create() to implement DECLARE_SEQ_BUF()
2026-10-28 23:19 [RFC v1] seq_buf: Add seq_buf_create() to implement DECLARE_SEQ_BUF() Alejandro Colomar
@ 2026-10-29 1:12 ` Steven Rostedt
2026-10-29 11:33 ` Alejandro Colomar
0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2026-10-29 1:12 UTC (permalink / raw)
To: Alejandro Colomar; +Cc: linux-hardening, Nathan Lynch, Kees Cook
On Thu, 29 Oct 2026 00:19:24 +0100
Alejandro Colomar <alx@kernel.org> wrote:
> This implements DECLARE_SEQ_BUF() in a way that is independent of the
> members of the structure.
>
> This will allow transitioning to a different implementation of seq_buf
> which uses pointers instead of sizes, on which I plan to work soon.
>
> The compiler should be able to optimize this out and produce the same
> code as before.
>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Nathan Lynch <nathanl@linux.ibm.com>
> Cc: Kees Cook <keescook@chromium.org>
> Signed-off-by: Alejandro Colomar <alx@kernel.org>
> ---
>
> Hi Steve, Kees,
>
> This is a patch that I could split from the rewrite using pointers, so
> we can apply it earlier to reduce the later diff.
>
> I've built a kernel with 'allmodconfig' to check that it's okay.
>
> The reason I need this patch is that we can't calculate the end pointer
> of the compound literal without passing it to a function. If you want
> me to hold this patch and send it together with the rest of the rewrite,
> I can also do that, but I thought this might be useful by itself.
>
>
> Have a lovely night!
> Alex
>
>
> include/linux/seq_buf.h | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
> index 9f2839e73f8a..facc5643c049 100644
> --- a/include/linux/seq_buf.h
> +++ b/include/linux/seq_buf.h
> @@ -25,10 +25,7 @@ struct seq_buf {
> };
>
> #define DECLARE_SEQ_BUF(NAME, SIZE) \
> - struct seq_buf NAME = { \
> - .buffer = (char[SIZE]) { 0 }, \
> - .size = SIZE, \
> - }
> + struct seq_buf NAME = seq_buf_create((char[SIZE]){0}, SIZE)
It can't use the DECLARE_* name as that is by default something that
can be used outside of a function:
DECLARE_SEQ_BUF(foo, 1024);
Needs to work. Just because nothing does that now, doesn't mean it will
not happen in the future. From my understanding, all DECLARE_* macros
for other types work this way.
-- Steve
>
> static inline void seq_buf_clear(struct seq_buf *s)
> {
> @@ -45,6 +42,15 @@ seq_buf_init(struct seq_buf *s, char *buf, unsigned int size)
> seq_buf_clear(s);
> }
>
> +static inline struct seq_buf
> +seq_buf_create(char *buf, unsigned int size)
> +{
> + struct seq_buf s;
> +
> + seq_buf_init(&s, buf, size);
> + return s;
> +}
> +
> /*
> * seq_buf have a buffer that might overflow. When this happens
> * len is set to be greater than size.
>
> Range-diff against v0:
> -: ------------ > 1: 9bda534b33f0 seq_buf: Add seq_buf_create() to implement DECLARE_SEQ_BUF()
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [RFC v1] seq_buf: Add seq_buf_create() to implement DECLARE_SEQ_BUF()
2026-10-29 1:12 ` Steven Rostedt
@ 2026-10-29 11:33 ` Alejandro Colomar
0 siblings, 0 replies; 3+ messages in thread
From: Alejandro Colomar @ 2026-10-29 11:33 UTC (permalink / raw)
To: Steven Rostedt
Cc: Alejandro Colomar, linux-hardening, Nathan Lynch, Kees Cook
[-- Attachment #1: Type: text/plain, Size: 3710 bytes --]
Hi Steve,
> Date: 2026-10-28 21:12:27-0400
> From: Steven Rostedt <rostedt@goodmis.org>
>
> On Thu, 29 Oct 2026 00:19:24 +0100
> Alejandro Colomar <alx@kernel.org> wrote:
>
> > This implements DECLARE_SEQ_BUF() in a way that is independent of the
> > members of the structure.
> >
> > This will allow transitioning to a different implementation of seq_buf
> > which uses pointers instead of sizes, on which I plan to work soon.
> >
> > The compiler should be able to optimize this out and produce the same
> > code as before.
> >
> > Cc: Steven Rostedt <rostedt@goodmis.org>
> > Cc: Nathan Lynch <nathanl@linux.ibm.com>
> > Cc: Kees Cook <keescook@chromium.org>
> > Signed-off-by: Alejandro Colomar <alx@kernel.org>
> > ---
> >
> > Hi Steve, Kees,
> >
> > This is a patch that I could split from the rewrite using pointers, so
> > we can apply it earlier to reduce the later diff.
> >
> > I've built a kernel with 'allmodconfig' to check that it's okay.
> >
> > The reason I need this patch is that we can't calculate the end pointer
> > of the compound literal without passing it to a function. If you want
> > me to hold this patch and send it together with the rest of the rewrite,
> > I can also do that, but I thought this might be useful by itself.
> >
> >
> > Have a lovely night!
> > Alex
> >
> >
> > include/linux/seq_buf.h | 14 ++++++++++----
> > 1 file changed, 10 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
> > index 9f2839e73f8a..facc5643c049 100644
> > --- a/include/linux/seq_buf.h
> > +++ b/include/linux/seq_buf.h
> > @@ -25,10 +25,7 @@ struct seq_buf {
> > };
> >
> > #define DECLARE_SEQ_BUF(NAME, SIZE) \
> > - struct seq_buf NAME = { \
> > - .buffer = (char[SIZE]) { 0 }, \
> > - .size = SIZE, \
> > - }
> > + struct seq_buf NAME = seq_buf_create((char[SIZE]){0}, SIZE)
>
> It can't use the DECLARE_* name as that is by default something that
> can be used outside of a function:
>
> DECLARE_SEQ_BUF(foo, 1024);
>
> Needs to work. Just because nothing does that now, doesn't mean it will
> not happen in the future. From my understanding, all DECLARE_* macros
> for other types work this way.
Hmmmm, then I would like to remove this macro entirely. It is not
possible to implement it for a structure that has '.p' and '.end'
without a function call.
It would only be implementable with constexpr (or constinit? C++ has too
many constsomething things that slightly differ, and I don't know which
is which) functions that can be called at file scope, but those don't
exist in C.
Would it be okay for you to remove this, and perhaps replace it with
direct calls to seq_buf_create()? Maybe like this:
#define SEQ_BUF_CREATE(SIZE) seq_buf_create((char[SIZE]){0}, SIZE)
...
int
main(void)
{
struct seq_buf foo = SEQ_BUF_CREATE(1024);
}
Have a lovely day!
Alex
>
> -- Steve
>
>
> >
> > static inline void seq_buf_clear(struct seq_buf *s)
> > {
> > @@ -45,6 +42,15 @@ seq_buf_init(struct seq_buf *s, char *buf, unsigned int size)
> > seq_buf_clear(s);
> > }
> >
> > +static inline struct seq_buf
> > +seq_buf_create(char *buf, unsigned int size)
> > +{
> > + struct seq_buf s;
> > +
> > + seq_buf_init(&s, buf, size);
> > + return s;
> > +}
> > +
> > /*
> > * seq_buf have a buffer that might overflow. When this happens
> > * len is set to be greater than size.
> >
> > Range-diff against v0:
> > -: ------------ > 1: 9bda534b33f0 seq_buf: Add seq_buf_create() to implement DECLARE_SEQ_BUF()
>
>
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-29 11:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28 23:19 [RFC v1] seq_buf: Add seq_buf_create() to implement DECLARE_SEQ_BUF() Alejandro Colomar
2026-10-29 1:12 ` Steven Rostedt
2026-10-29 11:33 ` Alejandro Colomar
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.