linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: "Ted Ts'o" <tytso@mit.edu>, Arnd Bergmann <arnd@arndb.de>,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	jack@suse.cz, Eric Biggers <ebiggers@google.com>,
	Ext4 Developers List <linux-ext4@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] ext4: avoid unused variable warning
Date: Wed, 10 Oct 2018 21:43:39 +0200	[thread overview]
Message-ID: <CANiq72nGxH=PTwiEQARiN-iminwECAMYe6-GJzCUh+V0mJ-=YQ@mail.gmail.com> (raw)
In-Reply-To: <20181010192658.GA27646@thunk.org>

Hi Ted,

On Wed, Oct 10, 2018 at 9:27 PM Theodore Y. Ts'o <tytso@mit.edu> wrote:
>
> On Wed, Oct 10, 2018 at 04:27:58PM +0200, Arnd Bergmann wrote:
> > The two new variables are only used in an #ifdef, so they cause a
> > warning without CONFIG_QUOTA:
> >
> > fs/ext4/super.c: In function 'parse_options':
> > fs/ext4/super.c:1977:26: error: unused variable 'grp_qf_name' [-Werror=unused-variable]
> >   char *p, *usr_qf_name, *grp_qf_name;
> >                           ^~~~~~~~~~~
> > fs/ext4/super.c:1977:12: error: unused variable 'usr_qf_name' [-Werror=unused-variable]
> >   char *p, *usr_qf_name, *grp_qf_name;
> >
> > Fixes: 20cefcdc2040 ("ext4: fix use-after-free race in ext4_remount()'s error path")
> > Signed-off-by: Arnd Bergmann <arnd@arndb.de>
>
> Hmm, I wonder if we should do something like:
>
> #define EXT4_UNUSED_VAR __attribute__ ((unused))

We have __maybe_unused already, so you can go ahead! :-)

(Also __always_unused, same definition as well, but here it does not may sense).

>
> and then we could do:
>
>         char *p, *usr_qf_name EXT4_UNUSED_VAR, *grp_qf_name EXT4_UNUSED_VAR;
>
> More generally, I wonder if this is something we should have defined
> for the whole kernel, as opposed to a one-off hack that ACPI and ext4
> subsystems use.  It's a little ugly, but I think it's much nicer than
> having extra #ifdefs such as:
>
>         char *p;
> #ifdef CONFIG_QUOTA
>         char *usr_qf_name, *grp_qf_name;
> #endif
>
> After all, the compiler is perfectly capable of ignoring variables
> which are unused.  And if it's only because of an #ifdef later in the
> function, it would be nice to not have an extra #ifdef in the variable
> declarations.

Indeed, it looks clean --- I like it.

Although I am not sure how people will feel about that :-) Someone may
argue that, for consistency, we shouldn't, because inside structs we
have to use #ifdefs still.

Cheers,
Miguel

  reply	other threads:[~2018-10-10 19:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-10 14:27 [PATCH] ext4: avoid unused variable warning Arnd Bergmann
2018-10-10 19:26 ` Theodore Y. Ts'o
2018-10-10 19:43   ` Miguel Ojeda [this message]
2018-10-10 19:43   ` Arnd Bergmann

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='CANiq72nGxH=PTwiEQARiN-iminwECAMYe6-GJzCUh+V0mJ-=YQ@mail.gmail.com' \
    --to=miguel.ojeda.sandonis@gmail.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=arnd@arndb.de \
    --cc=ebiggers@google.com \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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).