lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 10 Oct 2018 21:43:39 +0200
From:   Arnd Bergmann <arnd@...db.de>
To:     "Theodore Y. Ts'o" <tytso@....edu>, Arnd Bergmann <arnd@...db.de>,
        Andreas Dilger <adilger.kernel@...ger.ca>,
        Jan Kara <jack@...e.cz>, Eric Biggers <ebiggers@...gle.com>,
        linux-ext4@...r.kernel.org, linux-kernel@...r.kernel.org,
        Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
Subject: Re: [PATCH] ext4: avoid unused variable warning

On 10/10/18, Theodore Y. Ts'o <tytso@....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@...db.de>
>
> Hmm, I wonder if we should do something like:
>
> #define EXT4_UNUSED_VAR __attribute__ ((unused))
>
> 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.

I think the global __maybe_unused macro should work fine here.
I though about using that instead, but picked the #ifdef for
consistency with the other ifdef in the same function.

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

Another alternative that often results in more readable code is
to use a check like

        if (IS_ENABLED(CONFIG_QUOTA)) {
             ....
        }

around the conditional code instead of the #ifdef. This should usually
work unless the code accesses some struct members that are
also hidden in that #ifdef. I have not checked if that is the case here.

        Arnd

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ