linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] seq_buf: make DECLARE_SEQ_BUF() usable
@ 2024-01-16 14:09 Nathan Lynch via B4 Relay
  2024-01-16 19:40 ` Christophe JAILLET
  2024-01-17 14:32 ` Steven Rostedt
  0 siblings, 2 replies; 5+ messages in thread
From: Nathan Lynch via B4 Relay @ 2024-01-16 14:09 UTC (permalink / raw)
  To: Steven Rostedt (Google), Kees Cook; +Cc: linux-kernel, Nathan Lynch

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>


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] seq_buf: make DECLARE_SEQ_BUF() usable
  2024-01-16 14:09 [PATCH] seq_buf: make DECLARE_SEQ_BUF() usable Nathan Lynch via B4 Relay
@ 2024-01-16 19:40 ` Christophe JAILLET
  2024-01-16 20:09   ` Steven Rostedt
  2024-01-17 14:32 ` Steven Rostedt
  1 sibling, 1 reply; 5+ messages in thread
From: Christophe JAILLET @ 2024-01-16 19:40 UTC (permalink / raw)
  To: nathanl, Steven Rostedt (Google), Kees Cook; +Cc: linux-kernel

Le 16/01/2024 à 15:09, Nathan Lynch via B4 Relay a écrit :
> 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,				\
>   	}

Hi,

just removing the & in ".buffer = __ ## NAME ## _buffer, \" also works IIRC.

See [1], which unfortunately has been unnoticed.

CJ


[1]: 
https://lore.kernel.org/all/2a534333-b5f6-4b1d-b4b8-a1a71f91c3ff@wanadoo.fr/


>   
> 
> ---
> base-commit: 70d201a40823acba23899342d62bc2644051ad2e
> change-id: 20240112-declare-seq-buf-fix-9803b7e679bc
> 
> Best regards,


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] seq_buf: make DECLARE_SEQ_BUF() usable
  2024-01-16 19:40 ` Christophe JAILLET
@ 2024-01-16 20:09   ` Steven Rostedt
  0 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2024-01-16 20:09 UTC (permalink / raw)
  To: Christophe JAILLET; +Cc: nathanl, Kees Cook, linux-kernel

On Tue, 16 Jan 2024 20:40:29 +0100
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> Le 16/01/2024 à 15:09, Nathan Lynch via B4 Relay a écrit :
> > 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,				\
> >   	}  
> 
> Hi,
> 
> just removing the & in ".buffer = __ ## NAME ## _buffer, \" also works IIRC.
> 
> See [1], which unfortunately has been unnoticed.
> 
> CJ
> 
> 
> [1]: 
> https://lore.kernel.org/all/2a534333-b5f6-4b1d-b4b8-a1a71f91c3ff@wanadoo.fr/

I guess I missed that.

But it still doesn't fix this case:

 static DECLARE_SEQ_BUF(my_seq_buf, MYSB_SIZE);

Which this patch does.


-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] seq_buf: make DECLARE_SEQ_BUF() usable
  2024-01-16 14:09 [PATCH] seq_buf: make DECLARE_SEQ_BUF() usable Nathan Lynch via B4 Relay
  2024-01-16 19:40 ` Christophe JAILLET
@ 2024-01-17 14:32 ` Steven Rostedt
  2024-01-17 20:29   ` Kees Cook
  1 sibling, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2024-01-17 14:32 UTC (permalink / raw)
  To: Nathan Lynch via B4 Relay; +Cc: nathanl, Kees Cook, linux-kernel


Kees,

Are you OK with this change? I ran it through my tests and have another
pull request ready to go that includes this. But I don't want to send it
without an Acked-by from you.

Luckily, Linus is on non-voluntary vacation so we may still have time ;-)

-- Steve


On Tue, 16 Jan 2024 08:09:25 -0600
Nathan Lynch via B4 Relay <devnull+nathanl.linux.ibm.com@kernel.org> wrote:

> 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,


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] seq_buf: make DECLARE_SEQ_BUF() usable
  2024-01-17 14:32 ` Steven Rostedt
@ 2024-01-17 20:29   ` Kees Cook
  0 siblings, 0 replies; 5+ messages in thread
From: Kees Cook @ 2024-01-17 20:29 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Nathan Lynch via B4 Relay, nathanl, linux-kernel

On Wed, Jan 17, 2024 at 09:32:34AM -0500, Steven Rostedt wrote:
> 
> Kees,
> 
> Are you OK with this change? I ran it through my tests and have another
> pull request ready to go that includes this. But I don't want to send it
> without an Acked-by from you.

Yeah! This cleanly solves the lack of being able to add the "static",
etc.

Acked-by: Kees Cook <keescook@chromium.org>

-Kees

> 
> Luckily, Linus is on non-voluntary vacation so we may still have time ;-)
> 
> -- Steve
> 
> 
> On Tue, 16 Jan 2024 08:09:25 -0600
> Nathan Lynch via B4 Relay <devnull+nathanl.linux.ibm.com@kernel.org> wrote:
> 
> > 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,
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-17 20:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-16 14:09 [PATCH] seq_buf: make DECLARE_SEQ_BUF() usable Nathan Lynch via B4 Relay
2024-01-16 19:40 ` Christophe JAILLET
2024-01-16 20:09   ` Steven Rostedt
2024-01-17 14:32 ` Steven Rostedt
2024-01-17 20:29   ` Kees Cook

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).