linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bill Wendling <morbo@google.com>
To: Segher Boessenkool <segher@kernel.crashing.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Nathan Chancellor <nathan@kernel.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	clang-built-linux <clang-built-linux@googlegroups.com>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-toolchains@vger.kernel.org
Subject: Re: [PATCH v2 1/3] base: mark 'no_warn' as unused
Date: Tue, 27 Jul 2021 13:24:49 -0700	[thread overview]
Message-ID: <CAGG=3QUgnahba_-6hk6VoZW4T3a_Qa2KTBx4+DswNf_KBEWOmw@mail.gmail.com> (raw)
In-Reply-To: <CAGG=3QVWxdYnjZshsYVwf+jVj8Mb9=44SZA64cL0g414JncWGw@mail.gmail.com>

On Tue, Jul 27, 2021 at 1:22 PM Bill Wendling <morbo@google.com> wrote:
>
> On Tue, Jul 27, 2021 at 1:17 PM Segher Boessenkool
> <segher@kernel.crashing.org> wrote:
> >
> > 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.
> >
> Or better still, use sysfs_create_link_nowarn() instead of
> sysfs_create_link(). We'll just have to take the "__must_check"
> attribute off the sysfs_create_link_nowarn() declaration.
>
Strike that. I mistook the nowarn.
-bw

  reply	other threads:[~2021-07-27 20:25 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14  9:17 [PATCH 0/3] Fix clang -Wunused-but-set-variable warnings Bill Wendling
2021-07-14  9:17 ` [PATCH 1/3] base: remove unused variable 'no_warn' Bill Wendling
2021-07-14 12:15   ` kernel test robot
2021-07-14  9:17 ` [PATCH 2/3] bnx2x: remove unused variable 'cur_data_offset' Bill Wendling
2021-07-14  9:17 ` [PATCH 3/3] scsi: qla2xxx: remove unused variable 'status' Bill Wendling
2021-07-26 20:19 ` [PATCH v2 0/3] Fix clang -Wunused-but-set-variable warnings Bill Wendling
2021-07-26 20:19   ` [PATCH v2 1/3] base: mark 'no_warn' as unused Bill Wendling
2021-07-26 20:47     ` Nathan Chancellor
2021-07-26 21:01       ` Bill Wendling
2021-07-27  5:27       ` Greg Kroah-Hartman
2021-07-27  6:15         ` Bill Wendling
2021-07-27  6:41           ` Greg Kroah-Hartman
2021-07-27  7:08             ` Bill Wendling
2021-07-27  7:12               ` Greg Kroah-Hartman
2021-07-27  7:15                 ` Bill Wendling
2021-07-27 17:39             ` Nick Desaulniers
2021-07-27 17:42               ` Nick Desaulniers
2021-07-27 17:59               ` Greg Kroah-Hartman
2021-07-27 18:31                 ` Nick Desaulniers
2021-07-27 18:44                   ` Greg Kroah-Hartman
2021-07-27 19:02                     ` Nick Desaulniers
2021-07-27 19:23                 ` Bill Wendling
2021-07-27 20:13                 ` Segher Boessenkool
2021-07-27 20:22                   ` Bill Wendling
2021-07-27 20:24                     ` Bill Wendling [this message]
2021-07-27 18:32               ` Nathan Chancellor
2021-07-27 19:04                 ` Nick Desaulniers
2021-07-27 19:10                   ` Nathan Chancellor
2021-07-27 19:12                 ` Bill Wendling
2021-07-26 20:19   ` [PATCH v2 2/3] bnx2x: remove unused variable 'cur_data_offset' Bill Wendling
2021-07-26 20:36     ` Nathan Chancellor
2021-07-26 20:19   ` [PATCH v2 3/3] scsi: qla2xxx: remove unused variable 'status' Bill Wendling
2021-07-26 20:40     ` Nathan Chancellor
2021-07-27  3:14     ` Martin K. Petersen
2021-07-29  3:38   ` [PATCH v2 0/3] Fix clang -Wunused-but-set-variable warnings Martin K. Petersen

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='CAGG=3QUgnahba_-6hk6VoZW4T3a_Qa2KTBx4+DswNf_KBEWOmw@mail.gmail.com' \
    --to=morbo@google.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=rafael@kernel.org \
    --cc=segher@kernel.crashing.org \
    /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).