* QUERY: Inclusion of header files in kernel header files [not found] <22dbbef21002222241h711402f1me6b60ac7502cccd4@mail.gmail.com> @ 2010-02-23 6:43 ` viresh kumar 2010-02-23 6:59 ` Borislav Petkov 0 siblings, 1 reply; 12+ messages in thread From: viresh kumar @ 2010-02-23 6:43 UTC (permalink / raw) To: linux-kernel Hello, I have been through many kernel header files and have found that kernel header files at many places don't include other header files which they have dependency upon. For example: <linux/amba/bus.h> uses struct device and struct resource and it doesn't include <linux/device.h> and <linux/resource.h> header files. Now, whenever i try to include bus.h, i have to include device.h and resource.h. Is this correct approach? Again, if i include device.h and resource.h, they must be included before bus.h. Now this will disturb the alphabetical ordering of including header files sometimes. (not in this example) Any idea behind this philosophy. regards, viresh kumar ST Microelectronics India. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-23 6:43 ` QUERY: Inclusion of header files in kernel header files viresh kumar @ 2010-02-23 6:59 ` Borislav Petkov 2010-02-23 7:31 ` viresh kumar 0 siblings, 1 reply; 12+ messages in thread From: Borislav Petkov @ 2010-02-23 6:59 UTC (permalink / raw) To: viresh kumar; +Cc: linux-kernel From: viresh kumar <viresh.linux@gmail.com> Date: Tue, Feb 23, 2010 at 12:13:35PM +0530 Hi, > I have been through many kernel header files and have found that kernel header > files at many places don't include other header files which they have > dependency upon. > > For example: > <linux/amba/bus.h> uses struct device and struct resource and it doesn't > include <linux/device.h> and <linux/resource.h> header files. > > Now, whenever i try to include bus.h, i have to include device.h and resource.h. > > Is this correct approach? > > Again, if i include device.h and resource.h, they must be included before bus.h. and this is the thing: all those other files which include <linux/amba/bus.h> either include <linux/device.h> and <linux/resource.h> directly or the last are being included indirectly through other headers. Baseline, struct device and struct resource's definitions have to be available before <linux/amba/bus.h> is included. That's why you have to include the bus.h header last. > Now this will disturb the alphabetical ordering of including header files > sometimes. (not in this example) I don't think there's such thing as alphabetical header ordering and if it were it would be rather dumb thing to do. Hope this helps. -- Regards/Gruss, Boris. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-23 6:59 ` Borislav Petkov @ 2010-02-23 7:31 ` viresh kumar 2010-02-23 9:50 ` Borislav Petkov 0 siblings, 1 reply; 12+ messages in thread From: viresh kumar @ 2010-02-23 7:31 UTC (permalink / raw) To: Borislav Petkov, viresh kumar, linux-kernel Hi, >> Is this correct approach? >> >> Again, if i include device.h and resource.h, they must be included before bus.h. > > and this is the thing: all those other files which include > <linux/amba/bus.h> either include <linux/device.h> and > <linux/resource.h> directly or the last are being included indirectly > through other headers. > > Baseline, struct device and struct resource's definitions have to be > available before <linux/amba/bus.h> is included. That's why you have to > include the bus.h header last. > We need to include device.h and resource.h at every place where we use bus.h. Shouldn't it be responsibility of bus.h only? So that people don't have to bother about bus.h internal dependencies. I think, ideally including any header file shouldn't give compilation errors for types used in included header file. viresh kumar On Tue, Feb 23, 2010 at 12:29 PM, Borislav Petkov <petkovbb@googlemail.com> wrote: > From: viresh kumar <viresh.linux@gmail.com> > Date: Tue, Feb 23, 2010 at 12:13:35PM +0530 > > Hi, > >> I have been through many kernel header files and have found that kernel header >> files at many places don't include other header files which they have >> dependency upon. >> >> For example: >> <linux/amba/bus.h> uses struct device and struct resource and it doesn't >> include <linux/device.h> and <linux/resource.h> header files. >> >> Now, whenever i try to include bus.h, i have to include device.h and resource.h. >> >> Is this correct approach? >> >> Again, if i include device.h and resource.h, they must be included before bus.h. > > and this is the thing: all those other files which include > <linux/amba/bus.h> either include <linux/device.h> and > <linux/resource.h> directly or the last are being included indirectly > through other headers. > > Baseline, struct device and struct resource's definitions have to be > available before <linux/amba/bus.h> is included. That's why you have to > include the bus.h header last. > >> Now this will disturb the alphabetical ordering of including header files >> sometimes. (not in this example) > > I don't think there's such thing as alphabetical header ordering and if > it were it would be rather dumb thing to do. > > Hope this helps. > > -- > Regards/Gruss, > Boris. > ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-23 7:31 ` viresh kumar @ 2010-02-23 9:50 ` Borislav Petkov 2010-02-23 11:37 ` viresh kumar 0 siblings, 1 reply; 12+ messages in thread From: Borislav Petkov @ 2010-02-23 9:50 UTC (permalink / raw) To: viresh kumar; +Cc: linux-kernel From: viresh kumar <viresh.linux@gmail.com> Date: Tue, Feb 23, 2010 at 01:01:25PM +0530 > >> Again, if i include device.h and resource.h, they must be included before bus.h. > > > > and this is the thing: all those other files which include > > <linux/amba/bus.h> either include <linux/device.h> and > > <linux/resource.h> directly or the last are being included indirectly > > through other headers. > > > > Baseline, struct device and struct resource's definitions have to be > > available before <linux/amba/bus.h> is included. That's why you have to > > include the bus.h header last. > > > > We need to include device.h and resource.h at every place where we use bus.h. > > Shouldn't it be responsibility of bus.h only? So that people don't > have to bother about bus.h > internal dependencies. A quick grep in <include/linux/> reveals that most, if not all, of the headers that use struct resource, for example, include ioport.h which contains the definition. So yes, it should be like this, besides we guard against multiple inclusion with the #ifndef ..., #define... #endif thing anyway. > I think, ideally including any header file shouldn't give compilation > errors for types used in > included header file. Agreed. I'd send a patch fixing the bus.h header, in case no one has a valid technical reason against it. -- Regards/Gruss, Boris. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-23 9:50 ` Borislav Petkov @ 2010-02-23 11:37 ` viresh kumar 2010-02-23 13:01 ` Borislav Petkov 2010-02-23 15:15 ` Theodore Tso 0 siblings, 2 replies; 12+ messages in thread From: viresh kumar @ 2010-02-23 11:37 UTC (permalink / raw) To: Borislav Petkov, viresh kumar, linux-kernel >> I think, ideally including any header file shouldn't give compilation >> errors for types used in >> included header file. > > Agreed. > > I'd send a patch fixing the bus.h header, in case no one has a valid > technical reason against it. > That will be great!!! Actually this issue is not present only in bus.h, but some other kernel header files. Like: arch/arm/include/asm/clkdev.h don't include list.h file but using struct list_head May be we need to check this in other header files also. regards, viresh kumar ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-23 11:37 ` viresh kumar @ 2010-02-23 13:01 ` Borislav Petkov 2010-02-23 13:59 ` Stefan Richter 2010-02-24 4:23 ` viresh kumar 2010-02-23 15:15 ` Theodore Tso 1 sibling, 2 replies; 12+ messages in thread From: Borislav Petkov @ 2010-02-23 13:01 UTC (permalink / raw) To: viresh kumar; +Cc: Borislav Petkov, linux-kernel From: viresh kumar <viresh.linux@gmail.com> Date: Tue, Feb 23, 2010 at 05:07:47PM +0530 > >> I think, ideally including any header file shouldn't give compilation > >> errors for types used in > >> included header file. > > > > Agreed. > > > > I'd send a patch fixing the bus.h header, in case no one has a valid > > technical reason against it. > > > > That will be great!!! Just to make sure: with "I'd" I meant "I would", i.e. actually _you_ could send a patch fixing that by explaining the problem in the commit message :). > Actually this issue is not present only in bus.h, but some other > kernel header files. > Like: arch/arm/include/asm/clkdev.h don't include list.h file but > using struct list_head > > May be we need to check this in other header files also. Well, you should talk to the arm maintainer about that task and whether it is desirable. -- Regards/Gruss, Boris. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-23 13:01 ` Borislav Petkov @ 2010-02-23 13:59 ` Stefan Richter 2010-02-24 4:23 ` viresh kumar 1 sibling, 0 replies; 12+ messages in thread From: Stefan Richter @ 2010-02-23 13:59 UTC (permalink / raw) To: Borislav Petkov; +Cc: viresh kumar, Borislav Petkov, linux-kernel Borislav Petkov wrote: > From: viresh kumar <viresh.linux@gmail.com> >> Actually this issue is not present only in bus.h, but some other >> kernel header files. >> Like: arch/arm/include/asm/clkdev.h don't include list.h file but >> using struct list_head >> >> May be we need to check this in other header files also. > > Well, you should talk to the arm maintainer about that task and whether > it is desirable. I agree but feel compelled to add: While each header file should indeed include everything that is necessary to allow for arbitrary orders of inclusion of this header,¹ this is sometimes not possible for core kernel headers or architecture headers. An example over which I stumbled a few days ago: linux/wait.h cannot easily include linux/sched.h although it uses definitions from it. There is a direct circular dependency which can be easily resolved, but there are also dependencies at deeper levels of indirection which cannot be easily resolved. ---------- ¹) IOW each header should include everything which it uses. OTOH a user of that header should not rely on having its own dependencies included indirectly. -- Stefan Richter -=====-==-=- --=- =-=== http://arcgraph.de/sr/ ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-23 13:01 ` Borislav Petkov 2010-02-23 13:59 ` Stefan Richter @ 2010-02-24 4:23 ` viresh kumar 1 sibling, 0 replies; 12+ messages in thread From: viresh kumar @ 2010-02-24 4:23 UTC (permalink / raw) To: Borislav Petkov; +Cc: Borislav Petkov, linux-kernel > Just to make sure: with "I'd" I meant "I would", i.e. actually _you_ > could send a patch fixing that by explaining the problem in the commit > message :). > Yes boris, i will do that if everybody agrees. >> Actually this issue is not present only in bus.h, but some other >> kernel header files. >> Like: arch/arm/include/asm/clkdev.h don't include list.h file but >> using struct list_head >> > Well, you should talk to the arm maintainer about that task and whether > it is desirable. i will float a patch for the same in linux-arm mailing list. viresh. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-23 11:37 ` viresh kumar 2010-02-23 13:01 ` Borislav Petkov @ 2010-02-23 15:15 ` Theodore Tso 2010-02-24 4:28 ` viresh kumar 2010-02-24 10:38 ` Clemens Ladisch 1 sibling, 2 replies; 12+ messages in thread From: Theodore Tso @ 2010-02-23 15:15 UTC (permalink / raw) To: viresh kumar; +Cc: Borislav Petkov, linux-kernel On Feb 23, 2010, at 6:37 AM, viresh kumar wrote: > > Actually this issue is not present only in bus.h, but some other > kernel header files. > Like: arch/arm/include/asm/clkdev.h don't include list.h file but > using struct list_head > > May be we need to check this in other header files also. Before someone goes crazy and starts sending hundreds of patches to the trivial patch folks, please make sure that you only do this for places where header file foo uses "struct bar" in bar.h --- and NOT if it is using "struct bar *". Blind structure pointers don't cause compile failures, and is a perfectly good thing from the standpoint of data hiding. Also, it's highly desirable that as much as possible multiple inclusion is fixed up at the same time you add extra #includes into header files. Protecting against multiple inclusion is critical, yes, but even with the protection against multiple inclusion, the header file has to get parsed a second time, and that slows down kernel compiles. Regards, -- Ted ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-23 15:15 ` Theodore Tso @ 2010-02-24 4:28 ` viresh kumar 2010-02-24 7:02 ` Theodore Tso 2010-02-24 10:38 ` Clemens Ladisch 1 sibling, 1 reply; 12+ messages in thread From: viresh kumar @ 2010-02-24 4:28 UTC (permalink / raw) To: Theodore Tso; +Cc: Borislav Petkov, linux-kernel > Before someone goes crazy and starts sending hundreds of patches to the trivial patch folks, > please make sure that you only do this for places where header file foo uses "struct bar" in >bar.h --- and NOT if it is using "struct bar *". Blind structure pointers don't cause compile >failures, and is a perfectly good thing from the standpoint of data hiding. > Ted, Actually bus.h is using direct instances of these structures and thus it is giving compilation warnings. viresh. ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-24 4:28 ` viresh kumar @ 2010-02-24 7:02 ` Theodore Tso 0 siblings, 0 replies; 12+ messages in thread From: Theodore Tso @ 2010-02-24 7:02 UTC (permalink / raw) To: viresh kumar; +Cc: Borislav Petkov, linux-kernel On Feb 23, 2010, at 11:28 PM, viresh kumar wrote: >> Before someone goes crazy and starts sending hundreds of patches to the trivial patch folks, >> please make sure that you only do this for places where header file foo uses "struct bar" in >> bar.h --- and NOT if it is using "struct bar *". Blind structure pointers don't cause compile >> failures, and is a perfectly good thing from the standpoint of data hiding. >> > > Ted, > Actually bus.h is using direct instances of these structures and thus > it is giving compilation warnings. I'm aware of that --- in this case. However, this would not be the first time some over-eager kernel programmer newbie finds a message in LKML, reads it out of context, and then starts sending large number of useless, and even potentially harmful patches which all of the kernel maintainers then have to check and NACK. So while I was pretty sure you knew what you meant, the fact that other people were saying, "Yeah! Let's sweep through the header files finding all of these potential problems and clean them up," sent a chill down my spine. -- Ted ^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: QUERY: Inclusion of header files in kernel header files 2010-02-23 15:15 ` Theodore Tso 2010-02-24 4:28 ` viresh kumar @ 2010-02-24 10:38 ` Clemens Ladisch 1 sibling, 0 replies; 12+ messages in thread From: Clemens Ladisch @ 2010-02-24 10:38 UTC (permalink / raw) To: Theodore Tso; +Cc: viresh kumar, Borislav Petkov, linux-kernel Theodore Tso wrote: > Also, it's highly desirable that as much as possible multiple > inclusion is fixed up at the same time you add extra #includes into > header files. Protecting against multiple inclusion is critical, > yes, but even with the protection against multiple inclusion, the > header file has to get parsed a second time, and that slows down > kernel compiles. Multiple inclusion of a protected header does not hurt at all; gcc detects that a header file uses #ifdef/#endif header guards and automatically ignores any #include for that file if the symbol is already defined. Regards, Clemens ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2010-02-24 10:38 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <22dbbef21002222241h711402f1me6b60ac7502cccd4@mail.gmail.com>
2010-02-23 6:43 ` QUERY: Inclusion of header files in kernel header files viresh kumar
2010-02-23 6:59 ` Borislav Petkov
2010-02-23 7:31 ` viresh kumar
2010-02-23 9:50 ` Borislav Petkov
2010-02-23 11:37 ` viresh kumar
2010-02-23 13:01 ` Borislav Petkov
2010-02-23 13:59 ` Stefan Richter
2010-02-24 4:23 ` viresh kumar
2010-02-23 15:15 ` Theodore Tso
2010-02-24 4:28 ` viresh kumar
2010-02-24 7:02 ` Theodore Tso
2010-02-24 10:38 ` Clemens Ladisch
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox