Kernel header inclusion practice

Greg KH greg at kroah.com
Wed Jul 5 08:07:42 EDT 2017


On Wed, Jul 05, 2017 at 02:50:59PM +0800, Shiyao MA wrote:
> Hi,
> 
> How do you include the kernel headers?
> 
> For example,
> Currently I have the headers:
> #include <linux/module.h>
> #include <linux/kthread.h>
> #include <linux/delay.h>
> 
> And now I wanna use the  `struct workqueue_struct'. It turns out I
> don't have to include the "linux/workqueue.h".
> 
> So it must have already been included by the three headers above.
> 
> My question is:
> 
> What's the practice of including headers?
> Should I specifically include "linux/workqueue.h" ?

To be safe, yes, please do, sometimes other arches will not pull in the
.h files automatically that you expect them to.  So be specific.

> Another question is particular to the above three headers: does any of
> them guarantee to include the "linux/queue.h"?

Nope, if you need it, list it.

> If there is any documentation about the API of the headers (e.g., what
> they include), that will be great.

What exactly do you mean by this?

thanks,

greg k-h



More information about the Kernelnewbies mailing list