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.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Randy Dunlap <rdunlap@infradead.org>
Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
Message-ID: <
20251126214709.
2322314-1-andriy.shevchenko@linux.intel.com>
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)
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]))
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
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
18) Don't re-invent the kernel macros
-------------------------------------
-The header file include/linux/kernel.h contains a number of macros that
+There are 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
#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.
::
- #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)
/* 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;
}
* 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)
* {