Re: [PATCH 2/3] checkpatch: Add error on use of attribute((weak)) or __weak

From: Andrew Morton
Date: Wed Oct 15 2014 - 16:01:14 EST


On Wed, 15 Oct 2014 12:52:44 -0700 Joe Perches <joe@xxxxxxxxxxx> wrote:

> On Wed, 2014-10-15 at 12:50 -0700, Andrew Morton wrote:
> > On Wed, 15 Oct 2014 12:45:48 -0700 Joe Perches <joe@xxxxxxxxxxx> wrote:
> >
> > > On Wed, 2014-10-15 at 12:42 -0700, Andrew Morton wrote:
> > > > On Wed, 15 Oct 2014 12:32:08 -0700 Joe Perches <joe@xxxxxxxxxxx> wrote:
> > > >
> > > > > Using weak can have unintended link defects.
> > > > > Emit an error on its use.
> > > >
> > > > Well, we don't want a warning about use of __weak in function
> > > > definitions. Only in declarations.
> > >
> > > Why is that?
> >
> > Because the problem we're trying to detect is when __weak is used on a
> > declaration.
> >
> > This is OK:
> >
> > foo.h:
> > extern int foo(void);
> > foo.c:
> > int __weak foo(void)
> > {
> > ...
> > }
> >
> > But this is not OK:
> >
> > foo.h:
> > extern __weak int foo(void);
> > foo.c:
> > int __weak foo(void)
> > {
> > ...
> > }
> >
>
> And this?
>
> foo.c:
>
> extern __weak int foo(void);
>
> int __weak foo(void)
> {
> }
>

That's why I just said "And this bit maybe is checking for use in a
header file, which is not as good as checking for a declaration but is
probably good enough."

I don't think that would trigger the bug anyway. The problem is that

extern __weak int foo(void);

int foo(void)
{
}

unexpectedly and undesirably turns foo() into __weak.

I think it would be sufficient to check for __weak in a declaration.
If that isn't practical then checking for __weak in a .h file should
suffice.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/