From e07bf16bfda84f7bac83b6e8c6f4a5805249e6f5 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Tue, 21 Feb 2023 23:03:25 +0200 Subject: [PATCH 1/3] devicemodel: Remove duplicate owner assignment platform_driver_register() macro already does the correct assignment for the owner of the driver. Signed-off-by: Andy Shevchenko --- examples/devicemodel.c | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/devicemodel.c b/examples/devicemodel.c index f2d97dc..6fe923e 100644 --- a/examples/devicemodel.c +++ b/examples/devicemodel.c @@ -63,7 +63,6 @@ static struct platform_driver devicemodel_driver = { .driver = { .name = "devicemodel_example", - .owner = THIS_MODULE, .pm = &devicemodel_pm_ops, }, .probe = devicemodel_probe, From e62dff0df4baddcae6a07f229a644dd8700abe3c Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 22 Feb 2023 17:43:27 +0200 Subject: [PATCH 2/3] treewide: Clean up the headers The rule of thumb is to include the headers we are the direct user of. In particular, if we need an atomic API, we include . On the other hand we should not use headers for no reason. In particular, if we are not doing any IRQ job, why is the included? Signed-off-by: Andy Shevchenko --- examples/chardev.c | 10 +++++++--- examples/chardev2.c | 8 +++++--- examples/completions.c | 1 + examples/example_atomic.c | 3 ++- examples/example_mutex.c | 1 - examples/example_rwlock.c | 2 +- examples/example_spinlock.c | 1 - examples/sleep.c | 10 ++++++++-- 8 files changed, 24 insertions(+), 12 deletions(-) diff --git a/examples/chardev.c b/examples/chardev.c index a337d19..7972304 100644 --- a/examples/chardev.c +++ b/examples/chardev.c @@ -3,15 +3,19 @@ * you have read from the dev file */ +#include #include #include #include #include #include -#include -#include +#include /* for sprintf() */ #include -#include +#include +#include +#include /* for get_user and put_user */ + +#include /* Prototypes - this would normally go in a .h file */ static int device_open(struct inode *, struct file *); diff --git a/examples/chardev2.c b/examples/chardev2.c index 58ed57b..4c8b930 100644 --- a/examples/chardev2.c +++ b/examples/chardev2.c @@ -2,15 +2,17 @@ * chardev2.c - Create an input/output character device */ +#include #include #include #include #include #include -#include -#include /* We are doing kernel work */ #include /* Specifically, a module */ -#include +#include +#include + +#include #include "chardev.h" #define SUCCESS 0 diff --git a/examples/completions.c b/examples/completions.c index dddf5d7..197dea9 100644 --- a/examples/completions.c +++ b/examples/completions.c @@ -2,6 +2,7 @@ * completions.c */ #include +#include /* for IS_ERR() */ #include #include #include diff --git a/examples/example_atomic.c b/examples/example_atomic.c index 02d770f..4cd4897 100644 --- a/examples/example_atomic.c +++ b/examples/example_atomic.c @@ -1,7 +1,8 @@ /* * example_atomic.c */ -#include +#include +#include #include #include diff --git a/examples/example_mutex.c b/examples/example_mutex.c index 4eaf823..3149c23 100644 --- a/examples/example_mutex.c +++ b/examples/example_mutex.c @@ -1,7 +1,6 @@ /* * example_mutex.c */ -#include #include #include #include diff --git a/examples/example_rwlock.c b/examples/example_rwlock.c index 74a903f..9668e75 100644 --- a/examples/example_rwlock.c +++ b/examples/example_rwlock.c @@ -1,9 +1,9 @@ /* * example_rwlock.c */ -#include #include #include +#include static DEFINE_RWLOCK(myrwlock); diff --git a/examples/example_spinlock.c b/examples/example_spinlock.c index 5b69df1..862291b 100644 --- a/examples/example_spinlock.c +++ b/examples/example_spinlock.c @@ -2,7 +2,6 @@ * example_spinlock.c */ #include -#include #include #include #include diff --git a/examples/sleep.c b/examples/sleep.c index 931ff5d..dff612a 100644 --- a/examples/sleep.c +++ b/examples/sleep.c @@ -3,13 +3,19 @@ * at the same time, put all but one to sleep. */ +#include +#include #include /* We're doing kernel work */ #include /* Specifically, a module */ #include /* Necessary because we use proc fs */ -#include /* For putting processes to sleep and - waking them up */ +#include #include /* for get_user and put_user */ #include +#include /* For putting processes to sleep and + waking them up */ + +#include +#include #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0) #define HAVE_PROC_OPS From b8bbcd8a07a6fd124408804d7ea9a85a8d66d64f Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 23 Feb 2023 12:41:23 +0200 Subject: [PATCH 3/3] treewide: Replace kernel.h by printk.h The kernel.h should be discouraged for use. Signed-off-by: Andy Shevchenko --- examples/bottomhalf.c | 2 +- examples/completions.c | 2 +- examples/example_atomic.c | 2 +- examples/example_mutex.c | 2 +- examples/example_rwlock.c | 2 +- examples/example_spinlock.c | 2 +- examples/example_tasklet.c | 2 +- examples/hello-1.c | 2 +- examples/hello-2.c | 2 +- examples/hello-3.c | 2 +- examples/hello-4.c | 2 +- examples/hello-5.c | 3 ++- examples/intrpt.c | 3 ++- examples/sleep.c | 3 ++- lkmpg.tex | 2 +- 15 files changed, 18 insertions(+), 15 deletions(-) diff --git a/examples/bottomhalf.c b/examples/bottomhalf.c index 91be30e..a4cbf5e 100644 --- a/examples/bottomhalf.c +++ b/examples/bottomhalf.c @@ -11,8 +11,8 @@ #include #include #include -#include #include +#include /* Macro DECLARE_TASKLET_OLD exists for compatibiity. * See https://lwn.net/Articles/830964/ diff --git a/examples/completions.c b/examples/completions.c index 197dea9..e9a87c6 100644 --- a/examples/completions.c +++ b/examples/completions.c @@ -4,9 +4,9 @@ #include #include /* for IS_ERR() */ #include -#include #include #include +#include static struct { struct completion crank_comp; diff --git a/examples/example_atomic.c b/examples/example_atomic.c index 4cd4897..7ae8fb8 100644 --- a/examples/example_atomic.c +++ b/examples/example_atomic.c @@ -3,8 +3,8 @@ */ #include #include -#include #include +#include #define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c" #define BYTE_TO_BINARY(byte) \ diff --git a/examples/example_mutex.c b/examples/example_mutex.c index 3149c23..6baf61f 100644 --- a/examples/example_mutex.c +++ b/examples/example_mutex.c @@ -1,9 +1,9 @@ /* * example_mutex.c */ -#include #include #include +#include static DEFINE_MUTEX(mymutex); diff --git a/examples/example_rwlock.c b/examples/example_rwlock.c index 9668e75..3bdcb14 100644 --- a/examples/example_rwlock.c +++ b/examples/example_rwlock.c @@ -1,8 +1,8 @@ /* * example_rwlock.c */ -#include #include +#include #include static DEFINE_RWLOCK(myrwlock); diff --git a/examples/example_spinlock.c b/examples/example_spinlock.c index 862291b..483034f 100644 --- a/examples/example_spinlock.c +++ b/examples/example_spinlock.c @@ -2,8 +2,8 @@ * example_spinlock.c */ #include -#include #include +#include #include static DEFINE_SPINLOCK(sl_static); diff --git a/examples/example_tasklet.c b/examples/example_tasklet.c index 49c825e..bd894dc 100644 --- a/examples/example_tasklet.c +++ b/examples/example_tasklet.c @@ -3,8 +3,8 @@ */ #include #include -#include #include +#include /* Macro DECLARE_TASKLET_OLD exists for compatibility. * See https://lwn.net/Articles/830964/ diff --git a/examples/hello-1.c b/examples/hello-1.c index 0abcf64..12f1a5d 100644 --- a/examples/hello-1.c +++ b/examples/hello-1.c @@ -1,8 +1,8 @@ /* * hello-1.c - The simplest kernel module. */ -#include /* Needed for pr_info() */ #include /* Needed by all modules */ +#include /* Needed for pr_info() */ int init_module(void) { diff --git a/examples/hello-2.c b/examples/hello-2.c index b5c360d..d76e716 100644 --- a/examples/hello-2.c +++ b/examples/hello-2.c @@ -3,8 +3,8 @@ * This is preferred over using init_module() and cleanup_module(). */ #include /* Needed for the macros */ -#include /* Needed for pr_info() */ #include /* Needed by all modules */ +#include /* Needed for pr_info() */ static int __init hello_2_init(void) { diff --git a/examples/hello-3.c b/examples/hello-3.c index a82c385..84ea2c1 100644 --- a/examples/hello-3.c +++ b/examples/hello-3.c @@ -2,8 +2,8 @@ * hello-3.c - Illustrating the __init, __initdata and __exit macros. */ #include /* Needed for the macros */ -#include /* Needed for pr_info() */ #include /* Needed by all modules */ +#include /* Needed for pr_info() */ static int hello3_data __initdata = 3; diff --git a/examples/hello-4.c b/examples/hello-4.c index 8e2937d..c029761 100644 --- a/examples/hello-4.c +++ b/examples/hello-4.c @@ -2,8 +2,8 @@ * hello-4.c - Demonstrates module documentation. */ #include /* Needed for the macros */ -#include /* Needed for pr_info() */ #include /* Needed by all modules */ +#include /* Needed for pr_info() */ MODULE_LICENSE("GPL"); MODULE_AUTHOR("LKMPG"); diff --git a/examples/hello-5.c b/examples/hello-5.c index 5978e71..3447855 100644 --- a/examples/hello-5.c +++ b/examples/hello-5.c @@ -2,9 +2,10 @@ * hello-5.c - Demonstrates command line argument passing to a module. */ #include -#include +#include /* for ARRAY_SIZE() */ #include #include +#include #include MODULE_LICENSE("GPL"); diff --git a/examples/intrpt.c b/examples/intrpt.c index 0a6b252..beeddd6 100644 --- a/examples/intrpt.c +++ b/examples/intrpt.c @@ -10,8 +10,9 @@ #include #include -#include +#include /* for ARRAY_SIZE() */ #include +#include static int button_irqs[] = { -1, -1 }; diff --git a/examples/sleep.c b/examples/sleep.c index dff612a..ad8c1dd 100644 --- a/examples/sleep.c +++ b/examples/sleep.c @@ -5,8 +5,9 @@ #include #include -#include /* We're doing kernel work */ +#include /* for sprintf() */ #include /* Specifically, a module */ +#include #include /* Necessary because we use proc fs */ #include #include /* for get_user and put_user */ diff --git a/lkmpg.tex b/lkmpg.tex index d2fa59d..1976fee 100644 --- a/lkmpg.tex +++ b/lkmpg.tex @@ -401,7 +401,7 @@ The \cpp|cleanup_module()| function is supposed to undo whatever \cpp|init_modul Lastly, every kernel module needs to include \verb||. % TODO: adjust the section anchor -We needed to include \verb|| only for the macro expansion for the \cpp|pr_alert()| log level, which you'll learn about in Section \ref{sec:printk}. +We needed to include \verb|| only for the macro expansion for the \cpp|pr_alert()| log level, which you'll learn about in Section \ref{sec:printk}. \begin{enumerate} \item A point about coding style.