Re: [PATCH v2] ELF: add and use SUPPRESS_WARN_UNUSED_RESULT

From: Alexey Dobriyan
Date: Sat Jun 26 2021 - 02:47:01 EST


On Fri, Jun 25, 2021 at 04:30:40PM -0700, Andrew Morton wrote:
> On Sat, 26 Jun 2021 00:13:12 +0300 Alexey Dobriyan <adobriyan@xxxxxxxxx> wrote:
>
> > Last write to the "error" variable in load_elf_binary() is dead write.
> >
> > Add and use SUPPRESS_WARN_UNUSED_RESULT macro to express intent better.
> >
> > Credit goes to Ed Catmur:
> >
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425#c34
> >
> > Macro doesn't work for WUR functions returning structures and unions,
> > but it will work when gcc copies clang.
> >
> > ...
> >

> > #define __must_check __attribute__((__warn_unused_result__))
> > +/*
> > + * "(void)" is enough for clang but not for gcc.
> > + */
> > +#define SUPPRESS_WARN_UNUSED_RESULT (void)!
>
> That macro is rather ugly. Hopefully we won't really need it - how
> many such sites are there in a full kernel build anyway?

I don't know really. And they're hard to find because "(void)" doesn't
work and not everything is marked as WUR.

copy_from_user/copy_to_user are WUR but get_user/put_user aren't.
Logically they should bed. And if put_user() is WUR then I know another
place inside fork:

if (clone_flags & CLONE_PARENT_SETTID)
put_user(nr, args->parent_tid);