mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Joe Perches <joe@perches.com>
Cc: Andy Whitcroft <apw@canonical.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] checkpatch: Add error on use of attribute((weak)) or __weak
Date: Wed, 15 Oct 2014 13:01:02 -0700	[thread overview]
Message-ID: <20141015130102.43f322c4db1ed1bf736e97f1@linux-foundation.org> (raw)
In-Reply-To: <1413402764.7484.10.camel@perches.com>

On Wed, 15 Oct 2014 12:52:44 -0700 Joe Perches <joe@perches.com> 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@perches.com> 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@perches.com> 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.


  reply	other threads:[~2014-10-15 20:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-15 19:32 [PATCH 0/3] checkpatch: Miscellaneous cleanups Joe Perches
2014-10-15 19:32 ` [PATCH 1/3] checkpatch: Add an error test for no space before comma Joe Perches
2014-10-15 19:32 ` [PATCH 2/3] checkpatch: Add error on use of attribute((weak)) or __weak Joe Perches
2014-10-15 19:42   ` Andrew Morton
2014-10-15 19:45     ` Joe Perches
2014-10-15 19:50       ` Andrew Morton
2014-10-15 19:52         ` Joe Perches
2014-10-15 20:01           ` Andrew Morton [this message]
2014-10-15 20:46             ` [PATCH 2/3 V2] [PATCH] checkpatch: Add error on use of attribute((weak)) or __weak declarations Joe Perches
2014-10-15 19:32 ` [PATCH 3/3] checkpatch: Improve test for no space after cast Joe Perches

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=20141015130102.43f322c4db1ed1bf736e97f1@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.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

Powered by JetHome