On Wed, Oct 14, 2026 at 03:58:16PM -0700, Kees Cook wrote:
> In the very unlikely chance that a seq_operations didn't get initialized,
> we wouldn't want them calling some random location. As a first example
> user of __require_explicit_initialization, annotate them so a missing
> initializer is a compile-time warning.
> 
> Every seq_operations in the tree already sets all four, so no new warnings
> are added.
> 
> Signed-off-by: Kees Cook <[email protected]>
> ---
>  include/linux/seq_file.h | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
> index dc0e8c62d9e0..f0e7e52a0905 100644
> --- a/include/linux/seq_file.h
> +++ b/include/linux/seq_file.h
> @@ -28,11 +28,16 @@ struct seq_file {
>       void *private;
>  };
>  
> +/* All four are called without checking for NULL. */
>  struct seq_operations {
> -     void * (*start) (struct seq_file *m, loff_t *pos);
> -     void (*stop) (struct seq_file *m, void *v);
> -     void * (*next) (struct seq_file *m, void *v, loff_t *pos);
> -     int (*show) (struct seq_file *m, void *v);
> +     void *(*start)(struct seq_file *m, loff_t *pos)
> +             __require_explicit_initialization;
> +     void (*stop)(struct seq_file *m, void *v)
> +             __require_explicit_initialization;
> +     void *(*next)(struct seq_file *m, void *v, loff_t *pos)
> +             __require_explicit_initialization;
> +     int (*show)(struct seq_file *m, void *v)
> +             __require_explicit_initialization;
>  };

Hm, I acked the first patch, but seeing this "in the wild" is
interesting.  Feels kind of ackward, but I don't really know what to
suggest instead?  What about just making the lines longer:

        void *(*start)(struct seq_file *m, loff_t *pos)         
__require_explicit_initialization;
        void (*stop)(struct seq_file *m, void *v)               
__require_explicit_initialization;
        void *(*next)(struct seq_file *m, void *v, loff_t *pos) 
__require_explicit_initialization;
        int (*show)(struct seq_file *m, void *v)                
__require_explicit_initialization;

?

Anyway, I don't know.  I like this feature, and maybe it's going to be
used so infrequently it's not a big deal, but feels clunky.

thanks,

greg k-h

Reply via email to