Re: [PATCH] [PATCH v2] mm: initialize 'seq' in gup_fast to remove -Wmaybe-uninitialized warning

From: Andrew Morton

Date: Mon Mar 02 2026 - 16:32:30 EST


On Mon, 2 Mar 2026 22:34:05 +0300 Alexey Suchkov <aleks.koyf@xxxxxxxxx> wrote:

> The local variable 'seq' in gup_fast (mm/gup.c) was declared
> without initialization, which can trigger:
>
> mm/gup.c:3165:20: warning: ‘seq’ may be used uninitialized [-Wmaybe-uninitialized]
>
> Initialize 'seq' to 0. This does not change behavior, since
> read_seqcount_retry() always writes to it before use.
>
> ...
>
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -3131,7 +3131,7 @@ static unsigned long gup_fast(unsigned long start, unsigned long end,
> {
> unsigned long flags;
> int nr_pinned = 0;
> - unsigned seq;
> + unsigned int seq = 0;
>
> if (!IS_ENABLED(CONFIG_HAVE_GUP_FAST) ||
> !gup_fast_permitted(start, end))

stupid gcc. I liked uninitalized_var(), particularly for its
self-documenting nature. Never agreed with Linus's hate on it.

Thanks, I tweaked the changelog a bit:

: The local variable 'seq' in gup_fast (mm/gup.c) was declared
: without initialization, which with gcc-15.2.1 can trigger:
:
: mm/gup.c:3165:20: warning: `seq' may be used uninitialized [-Wmaybe-uninitialized]
:
: Work around this by initializing 'seq' to 0. This does not change
: behavior, since read_seqcount_retry() always writes to it before use.