Skip to contentSkip to conversation

docs: Update documentation to avoid mentioning of kernel.h

PATCH Superseded Andy Shevchenko 2 participants 12 messages Nov 26, 2025

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 docs: Update documentation to avoid mentioning of kernel.h

For several years, and still ongoing, the kernel.h is being split to smaller and narrow headers to avoid "including everything" approach which is bad in many ways. Since that, documentation missed a few required updates to align with that work. Do it here.

Note, language translations are left untouched and if anybody willing to help, please provide path(es) based on the updated English variant.

---
 Documentation/core-api/kobject.rst              |  2 +-
 Documentation/dev-tools/checkpatch.rst          |  2 +-
 Documentation/driver-api/basics.rst             | 17 ++++++++++++++++-
 .../driver-api/driver-model/design-patterns.rst |  2 +-
 Documentation/process/coding-style.rst          | 10 +++++++---
 Documentation/staging/rpmsg.rst                 |  7 +++++--
 6 files changed, 31 insertions(+), 9 deletions(-)
Documentation/core-api/kobject.rst +1 -1
index 7310247310a0..5f6c61bc03bf 100644
@@ -78,7 +78,7 @@ just a matter of using the kobj member.  Code that works with kobjects will
 often have the opposite problem, however: given a struct kobject pointer,
 what is the pointer to the containing structure?  You must avoid tricks
 (such as assuming that the kobject is at the beginning of the structure)
-and, instead, use the container_of() macro, found in ``<linux/kernel.h>``::
+and, instead, use the container_of() macro, found in ``<linux/container_of.h>``::
 
     container_of(ptr, type, member)
 
Documentation/dev-tools/checkpatch.rst +1 -1
index fa2988dd4657..c1dff8e6bccb 100644
@@ -753,7 +753,7 @@ Macros, Attributes and Symbols
     sizeof(foo)/sizeof(foo[0]) for finding number of elements in an
     array.
 
-    The macro is defined in include/linux/kernel.h::
+    The macro is defined in include/linux/array_size.h::
 
       #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
Documentation/driver-api/basics.rst +16 -1
index 5e9f7aee71a7..8b6a5888cb11 100644
@@ -114,10 +114,25 @@ Kernel objects manipulation
 Kernel utility functions
 ------------------------
 
-.. kernel-doc:: include/linux/kernel.h
+.. kernel-doc:: include/linux/array_size.h
+   :internal:
+
+.. kernel-doc:: include/linux/container_of.h
+   :internal:
+
+.. kernel-doc:: include/linux/kstrtox.h
    :internal:
    :no-identifiers: kstrtol kstrtoul
 
+.. kernel-doc:: include/linux/stddef.h
+   :internal:
+
+.. kernel-doc:: include/linux/util_macros.h
+   :internal:
+
+.. kernel-doc:: include/linux/wordpart.h
+   :internal:
+
 .. kernel-doc:: kernel/printk/printk.c
    :export:
    :no-identifiers: printk
Documentation/driver-api/driver-model/design-patterns.rst +1 -1
index 41eb8f41f7dd..965b2b93be6f 100644
@@ -103,7 +103,7 @@ The design pattern is the same for an hrtimer or something similar that will
 return a single argument which is a pointer to a struct member in the
 callback.
 
-container_of() is a macro defined in <linux/kernel.h>
+container_of() is a macro defined in <linux/container_of.h>
 
 What container_of() does is to obtain a pointer to the containing struct from
 a pointer to a member by a simple subtraction using the offsetof() macro from
Documentation/process/coding-style.rst +7 -3
index 2969ca378dbb..d63ea0bffdfe 100644
@@ -1070,7 +1070,7 @@ readability.
 18) Don't re-invent the kernel macros
 -------------------------------------
 
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that
 you should use, rather than explicitly coding some variant of them yourself.
 For example, if you need to calculate the length of an array, take advantage
 of the macro
@@ -1079,14 +1079,18 @@ of the macro
 
 	#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
+which is defined in array_size.h.
+
 Similarly, if you need to calculate the size of some structure member, use
 
 .. code-block:: c
 
 	#define sizeof_field(t, f) (sizeof(((t*)0)->f))
 
-There are also min() and max() macros that do strict type checking if you
-need them.  Feel free to peruse that header file to see what else is already
+which is defined in stddef.h.
+
+There are also min() and max() macros defined in minmax.h that do strict type checking if you
+need them.  Feel free to peruse the header files to see what else is already
 defined that you shouldn't reproduce in your code.
 
 
Documentation/staging/rpmsg.rst +5 -2
index 40282cca86ca..42bac1149d9d 100644
@@ -224,9 +224,12 @@ content to the console.
 
 ::
 
-  #include <linux/kernel.h>
+  #include <linux/dev_printk.h>
+  #include <linux/mod_devicetable.h>
   #include <linux/module.h>
+  #include <linux/printk.h>
   #include <linux/rpmsg.h>
+  #include <linux/types.h>
 
   static void rpmsg_sample_cb(struct rpmsg_channel *rpdev, void *data, int len,
 						void *priv, u32 src)
@@ -244,7 +247,7 @@ content to the console.
 	/* send a message on our channel */
 	err = rpmsg_send(rpdev->ept, "hello!", 6);
 	if (err) {
-		pr_err("rpmsg_send failed: %d\n", err);
+		dev_err(&rpdev->dev, "rpmsg_send failed: %d\n", err);
 		return err;
 	}
 
Signature · 1 line
2.50.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Andy Shevchenko

For several years, and still ongoing, the kernel.h is being split to smaller and narrow headers to avoid "including everything" approach which is bad in many ways. Since that, documentation missed a few required updates to align with that work. Do it here.

Note, language translations are left untouched and if anybody willing to help, please provide path(es) based on the updated English variant.

---
 Documentation/core-api/kobject.rst              |  2 +-
 Documentation/dev-tools/checkpatch.rst          |  2 +-
 Documentation/driver-api/basics.rst             | 17 ++++++++++++++++-
 .../driver-api/driver-model/design-patterns.rst |  2 +-
 Documentation/process/coding-style.rst          | 10 +++++++---
 Documentation/staging/rpmsg.rst                 |  7 +++++--
 6 files changed, 31 insertions(+), 9 deletions(-)
Documentation/process/coding-style.rst +0 -0
index 2969ca378dbb..d63ea0bffdfe 100644

Documentation/process/coding-style.rst readability. · line 1073

Quoted 5 lines
Documentation/process/coding-style.rst +1 -1
@@ -1070,7 +1070,7 @@ readability.
 18) Don't re-invent the kernel macros
 -------------------------------------
 
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that

There are many

Documentation/process/coding-style.rst readability. · line 1076

Quoted 3 lines
Documentation/process/coding-style.rst +0 -0
 you should use, rather than explicitly coding some variant of them yourself.
 For example, if you need to calculate the length of an array, take advantage
 of the macro

Otherwise LGTM. Thanks.

Signature · 1 line
~Randy
#2 lore raw
Quoted 1 line · Randy Dunlap

On 11/26/25 12:59 PM, Andy Shevchenko wrote:

...

Quoted 5 lines

Documentation/process/coding-style.rst readability. · line 1073

Quoted 2 lines
Documentation/process/coding-style.rst +1 -1
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that

There are many

Quoted 7 lines
Quoted 3 lines

you should use, rather than explicitly coding some variant of them yourself. For example, if you need to calculate the length of an array, take advantage of the macro

Otherwise LGTM. Thanks.

Thanks!

Can you also test it? I hope it will be not so broken (as some of the files seems never were before in the generated docs).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
reviewer
#3 lore raw
Quoted 14 lines · Andy Shevchenko
Quoted 1 line · Randy Dunlap

On 11/26/25 12:59 PM, Andy Shevchenko wrote:

...

Quoted 9 lines

Documentation/process/coding-style.rst readability. · line 1073

Quoted 2 lines
Documentation/process/coding-style.rst +1 -1
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that

There are many

Quoted 3 lines

you should use, rather than explicitly coding some variant of them yourself. For example, if you need to calculate the length of an array, take advantage of the macro

Quoted 8 lines
Quoted 3 lines

Otherwise LGTM. Thanks.

Thanks!

Can you also test it? I hope it will be not so broken (as some of the files seems never were before in the generated docs).

It's not completely happy:

linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:125: ERROR: Unexpected indentation. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:123: WARNING: Inline emphasis start-string without end-string. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:126: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:130: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]

Signature · 1 line
~Randy
reviewer
#4 lore raw
Quoted 26 lines · Randy Dunlap
Quoted 14 lines · Andy Shevchenko
Quoted 1 line · Randy Dunlap

On 11/26/25 12:59 PM, Andy Shevchenko wrote:

...

Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that

There are many

Quoted 3 lines

you should use, rather than explicitly coding some variant of them yourself. For example, if you need to calculate the length of an array, take advantage of the macro

Quoted 8 lines
Quoted 3 lines

Otherwise LGTM. Thanks.

Thanks!

Can you also test it? I hope it will be not so broken (as some of the files seems never were before in the generated docs).

Quoted 8 lines

It's not completely happy:

linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:125: ERROR: Unexpected indentation. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:123: WARNING: Inline emphasis start-string without end-string. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:126: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:130: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]

This little change fixes it for me. Just include it in your patch, please.

---
 include/linux/util_macros.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/util_macros.h +1 -1
@@ -119,7 +119,7 @@
  * a fuss about it. This makes the programmer responsible for tagging
  * the functions that can be garbage-collected.
  *
- * With the macro it is possible to write the following:
+ * With the macro it is possible to write the following::
  *
  *     static int foo_suspend(struct device *dev)
  *     {
Signature · 1 line
~Randy
#5 lore raw
Quoted 4 lines · Randy Dunlap
Quoted 3 lines · Randy Dunlap
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Randy Dunlap

On 11/26/25 12:59 PM, Andy Shevchenko wrote:

...

Quoted 20 lines
Quoted 20 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that

There are many

Quoted 3 lines

you should use, rather than explicitly coding some variant of them yourself. For example, if you need to calculate the length of an array, take advantage of the macro

Quoted 8 lines
Quoted 3 lines

Otherwise LGTM. Thanks.

Thanks!

Can you also test it? I hope it will be not so broken (as some of the files seems never were before in the generated docs).

It's not completely happy:

Quoted 7 lines
Quoted 5 lines

linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:125: ERROR: Unexpected indentation. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:123: WARNING: Inline emphasis start-string without end-string. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:126: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:130: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]

This little change fixes it for me. Just include it in your patch, please.

Thanks, just 15 sec before your message I guessed the same fix.

Quoted 7 lines
---
 include/linux/util_macros.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

include/linux/util_macros.h line 125

Quoted 8 lines
include/linux/util_macros.h +1 -1
@@ -119,7 +119,7 @@
  * a fuss about it. This makes the programmer responsible for tagging
  * the functions that can be garbage-collected.
  *
- * With the macro it is possible to write the following:
+ * With the macro it is possible to write the following::
  *
  *     static int foo_suspend(struct device *dev)
  *     {

Since it's like this, I just fix both places you pointed out and issue a v2. May I have ypour Tested-by ten?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
reviewer Tested-by
#6 lore raw
Quoted 42 lines · Andy Shevchenko
Quoted 4 lines · Randy Dunlap
Quoted 3 lines · Randy Dunlap
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Randy Dunlap

On 11/26/25 12:59 PM, Andy Shevchenko wrote:

...

Quoted 20 lines
Quoted 20 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that

There are many

Quoted 3 lines

you should use, rather than explicitly coding some variant of them yourself. For example, if you need to calculate the length of an array, take advantage of the macro

Quoted 8 lines
Quoted 3 lines

Otherwise LGTM. Thanks.

Thanks!

Can you also test it? I hope it will be not so broken (as some of the files seems never were before in the generated docs).

It's not completely happy:

Quoted 7 lines
Quoted 5 lines

linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:125: ERROR: Unexpected indentation. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:123: WARNING: Inline emphasis start-string without end-string. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:126: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:130: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]

This little change fixes it for me. Just include it in your patch, please.

Thanks, just 15 sec before your message I guessed the same fix.

Quoted 4 lines
---
 include/linux/util_macros.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

include/linux/util_macros.h line 125

Quoted 11 lines
include/linux/util_macros.h +1 -1
@@ -119,7 +119,7 @@
  * a fuss about it. This makes the programmer responsible for tagging
  * the functions that can be garbage-collected.
  *
- * With the macro it is possible to write the following:
+ * With the macro it is possible to write the following::
  *
  *     static int foo_suspend(struct device *dev)
  *     {

Since it's like this, I just fix both places you pointed out and issue a v2. May I have ypour Tested-by ten?

Yes.

Signature · 1 line
~Randy
#7 lore raw
Quoted 1 line · Randy Dunlap

On 11/26/25 1:42 PM, Andy Shevchenko wrote:

...

Quoted 5 lines
Quoted 2 lines

Since it's like this, I just fix both places you pointed out and issue a v2. May I have ypour Tested-by ten?

Yes.

Thanks, but I have just sent it out, please reply there.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw
In reply to Randy Dunlap
Quoted 3 lines · Randy Dunlap
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Randy Dunlap

On 11/26/25 12:59 PM, Andy Shevchenko wrote:

...

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Documentation/process/coding-style.rst readability. · line 1073

Quoted 2 lines
Documentation/process/coding-style.rst +1 -1
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that

There are many

Quoted 3 lines

you should use, rather than explicitly coding some variant of them yourself. For example, if you need to calculate the length of an array, take advantage of the macro

Otherwise LGTM. Thanks.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Thanks!

Can you also test it? I hope it will be not so broken (as some of the files seems never were before in the generated docs).

It's not completely happy:

A-ha, thanks for trying!

Quoted 4 lines

linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:125: ERROR: Unexpected indentation. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:123: WARNING: Inline emphasis start-string without end-string. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:126: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:130: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]

I will look at it tomorrow, but can you remove this (or even fix) and check the rest meanwhile?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
reviewer
#9 lore raw
Quoted 29 lines · Andy Shevchenko
Quoted 3 lines · Randy Dunlap
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Randy Dunlap

On 11/26/25 12:59 PM, Andy Shevchenko wrote:

...

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Documentation/process/coding-style.rst readability. · line 1073

Quoted 2 lines
Documentation/process/coding-style.rst +1 -1
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that

There are many

Quoted 3 lines

you should use, rather than explicitly coding some variant of them yourself. For example, if you need to calculate the length of an array, take advantage of the macro

Otherwise LGTM. Thanks.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Thanks!

Can you also test it? I hope it will be not so broken (as some of the files seems never were before in the generated docs).

It's not completely happy:

A-ha, thanks for trying!

Quoted 8 lines
Quoted 4 lines

linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:125: ERROR: Unexpected indentation. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:123: WARNING: Inline emphasis start-string without end-string. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:126: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:130: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]

I will look at it tomorrow, but can you remove this (or even fix) and check the rest meanwhile?

That was the only docs warnings caused by your patch (at least in my testing). and now easily fixed.

Signature · 1 line
~Randy
#10 lore raw
In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Randy Dunlap
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Randy Dunlap

On 11/26/25 12:59 PM, Andy Shevchenko wrote:

...

Quoted 22 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Documentation/process/coding-style.rst readability. · line 1073

Quoted 2 lines
Documentation/process/coding-style.rst +1 -1
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that

There are many

Quoted 3 lines

you should use, rather than explicitly coding some variant of them yourself. For example, if you need to calculate the length of an array, take advantage of the macro

Otherwise LGTM. Thanks.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Thanks!

Can you also test it? I hope it will be not so broken (as some of the files seems never were before in the generated docs).

It's not completely happy:

A-ha, thanks for trying!

Quoted 8 lines
Quoted 4 lines

linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:125: ERROR: Unexpected indentation. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:123: WARNING: Inline emphasis start-string without end-string. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:126: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:130: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]

I will look at it tomorrow, but can you remove this (or even fix) and check the rest meanwhile?

At glance seems like colon is missing, should be :: instead of : in near lines.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
reviewer
#11 lore raw
Quoted 36 lines · Andy Shevchenko
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Randy Dunlap
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Randy Dunlap

On 11/26/25 12:59 PM, Andy Shevchenko wrote:

...

Quoted 28 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Documentation/process/coding-style.rst readability. · line 1073

Quoted 2 lines
Documentation/process/coding-style.rst +1 -1
-The header file include/linux/kernel.h contains a number of macros that
+There many header files in include/linux/ that contain a number of macros that

There are many

Quoted 3 lines

you should use, rather than explicitly coding some variant of them yourself. For example, if you need to calculate the length of an array, take advantage of the macro

Otherwise LGTM. Thanks.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Thanks!

Can you also test it? I hope it will be not so broken (as some of the files seems never were before in the generated docs).

It's not completely happy:

A-ha, thanks for trying!

Quoted 4 lines

linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:125: ERROR: Unexpected indentation. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:123: WARNING: Inline emphasis start-string without end-string. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:126: WARNING: Block quote ends without a blank line; unexpected unindent. [docutils] linux-next-20251126/Documentation/driver-api/basics:130: ../include/linux/util_macros.h:130: WARNING: Definition list ends without a blank line; unexpected unindent. [docutils]

Quoted 5 lines
Quoted 2 lines

I will look at it tomorrow, but can you remove this (or even fix) and check the rest meanwhile?

At glance seems like colon is missing, should be :: instead of : in near lines.

Yes, that's what I sent earlier :)

Signature · 1 line
~Randy