linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Gortmaker <paul.gortmaker@windriver.com>
To: Sam Ravnborg <sam@ravnborg.org>
Cc: Fabio Estevam <fabio.estevam@freescale.com>,
	<linux-kernel@vger.kernel.org>, <akpm@linux-foundation.org>,
	<linux@arm.linux.org.uk>
Subject: Re: [PATCH] kernel.h: Include <linux/bug.h> to avoid build	breakage with ARRAY_SIZE()
Date: Tue, 28 Feb 2012 11:43:36 -0500	[thread overview]
Message-ID: <4F4D0438.9070200@windriver.com> (raw)
In-Reply-To: <20120228155124.GA2827@merkur.ravnborg.org>

On 12-02-28 10:51 AM, Sam Ravnborg wrote:
> On Tue, Feb 28, 2012 at 10:41:39AM -0300, Fabio Estevam wrote:
>> Building imx_v6_v7_defconfig generated the following build error:
>>
>> arch/arm/mach-imx/cpu_op-mx51.c: In function 'mx51_get_cpu_op':
>> arch/arm/mach-imx/cpu_op-mx51.c:27: error: implicit declaration of function 'BUILD_BUG_ON_ZERO'
>>
>> commit 6f863554 (kernel.h: doesn't explicitly use bug.h, so don't include it.)
>> has removed asm/debug.h from linux/kernel.h.
>>
>> Quoting Russell King (http://www.spinics.net/lists/arm-kernel/msg161916.html)
>>
>> "linux/kernel.h _does_ use bug stuff - in ARRAY_SIZE().
>>
>> ARRAY_SIZE() uses __must_be_array(), which is defined in linux/compiler-gcc.h,
>> which is obtained via linux/compiler.h and linux/linkage.h.
>>
>> linux/compiler-gcc.h defines __must_be_array() to be:
>> #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
> 
> In which case linux/compiler-gcc.h uses bug.h - so this is where you
> should add the include.
> Not in kernel.h that just happens to use __must_be_array()
> We do not want to add "#include bug.h" to all header files
> that happens to use __must_be_array.

The approach I was taking was to consider something "used" if it was
actually in a static inline[1].  So in that sense, the kernel.h does
not "use" ARRAY_SIZE, but only defines it.  This seems to be what has
been done in the past, and folks have even converted trivial static
inline functions to macros just to use this concept of "used" to
help avoid tangling includes any further than they currently are.

If we expand the definition of used to cover the #define case, then
we'll pretty much have all headers implicitly present everywhere,
and folks won't have a clue what functions they are actually making
use of.  They'll be able to get away with including kernel.h and
largely nothing else - having everything implicitly present, I think.

rmk's example about the uncompressor code is a good one I think, in
terms of having to be explicit about what you are using/including,
since it forces people to think a bit more about what they are using.

So, sticking bug.h into another header that is largely present in
every compile was something that I was actually trying to avoid if
possible....  maybe I should abandon that goal?

Paul.

[1] https://lkml.org/lkml/2012/1/26/529

> 
> 	Sam

  reply	other threads:[~2012-02-28 16:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-28 13:41 [PATCH] kernel.h: Include <linux/bug.h> to avoid build breakage with ARRAY_SIZE() Fabio Estevam
2012-02-28 15:51 ` Sam Ravnborg
2012-02-28 16:43   ` Paul Gortmaker [this message]
2012-02-28 20:06     ` Sam Ravnborg
2012-03-02  1:15 ` [PATCH v2] compiler.h: " Fabio Estevam
2012-03-02  2:49   ` Paul Gortmaker
2012-03-02  3:13     ` Fabio Estevam
2012-03-02 14:22       ` Paul Gortmaker
2012-04-04 14:29         ` Uwe Kleine-König
2012-04-05 18:35           ` Paul Gortmaker
2012-04-05 18:52             ` Uwe Kleine-König

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=4F4D0438.9070200@windriver.com \
    --to=paul.gortmaker@windriver.com \
    --cc=akpm@linux-foundation.org \
    --cc=fabio.estevam@freescale.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=sam@ravnborg.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).