[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210727201328.GY1583@gate.crashing.org>
Date: Tue, 27 Jul 2021 15:13:28 -0500
From: Segher Boessenkool <segher@...nel.crashing.org>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Nick Desaulniers <ndesaulniers@...gle.com>,
Bill Wendling <morbo@...gle.com>,
Nathan Chancellor <nathan@...nel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>,
clang-built-linux <clang-built-linux@...glegroups.com>,
LKML <linux-kernel@...r.kernel.org>,
linux-toolchains@...r.kernel.org
Subject: Re: [PATCH v2 1/3] base: mark 'no_warn' as unused
On Tue, Jul 27, 2021 at 07:59:24PM +0200, Greg Kroah-Hartman wrote:
> On Tue, Jul 27, 2021 at 10:39:49AM -0700, Nick Desaulniers wrote:
> > I think warn_unused_result should only really be used for functions
> > where the return value should be used 100% of the time.
>
> I too want a shiny new pony.
>
> But here in the real world, sometimes you have functions that for 99% of
> the users, you do want them to check the return value, but when you use
> them in core code or startup code, you "know" you are safe to ignore the
> return value.
>
> That is the case here. We have other fun examples of where people have
> tried to add error handling to code that runs at boot that have actually
> introduced security errors and they justify it with "but you have to
> check error values!"
>
> > If there are
> > cases where it's ok to not check the return value, consider not using
> > warn_unused_result on function declarations.
>
> Ok, so what do you do when you have a function like this where 99.9% of
> the users need to check this? Do I really need to write a wrapper
> function just for it so that I can use it "safely" in the core code
> instead?
>
> Something like:
>
> void do_safe_thing_and_ignore_the_world(...)
> {
> __unused int error;
>
> error = do_thing(...);
> }
>
> Or something else to get the compiler to be quiet about error being set
> and never used?
The simplest is to write
if (do_thing()) {
/* Nothing here, we can safely ignore the return value
* here, because of X and Y and I don't know, I have no
* idea actually why we can in this example. Hopefully
* in real code people do have a good reason :-)
*/
}
which should work in *any* compiler, doesn't need any extension, is
quite elegant, and encourages documenting why we ignore the return
value here.
Segher
Powered by blists - more mailing lists