Commit Graph

14 Commits

Author SHA1 Message Date
Andy Shevchenko
e62dff0df4 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 <linux/atomic.h>.

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 <linux/irq.h> included?

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
2023-02-23 12:54:30 +02:00
linD026
95a7ca513f Fix the buffer length may cause a read error
Since The length of the message buffer is BUF_LEN. When writing the
BUF_LEN length of the string it will overwrite the last character
(usually it is '\0' from the initialization). And, because the read
operation uses the character in the message buffer ('\0') to stop the
read loop. It will cause the read operation will read out of the
message buffer when the length parameter of read() is not lower than
or equal to BUF_LEN. So add one more byte space to avoid this problem.
2022-09-08 06:08:04 +08:00
Steven Lung
5ca9b642a4 Fix typo, grammar and remove duplicated words
Replaced 'a' with 'an' since a vowel sound is after.
2022-03-07 16:56:13 +08:00
linD026
1a6fb67cf2
Fix potential concurrent access problems with VFS (#108)
Since Linux v3.14, the read, write and seek operations of "struct file" are
guaranteed for thread safety [1][2]. This patch added an explanation.

Here are the potential problems:
chardev.c:
- Move the "msg_ptr" pointer into the read function to remove unnecessary usage.
- List the clear states of "already_open" by using mnemonic enumeration.

chardev2.c:
- The "buffer" in the write function is user space data. It cannot use in the
  kernel space.
- Reduce the redundant type transformation.
- List the states of "already_open". Same as chardev.c.

[1] https://lore.kernel.org/lkml/20140303210359.26624.qmail@science.horizon.com/T/#u
[2] 9c225f2655
2021-09-23 12:20:10 +08:00
linD026
148fb013ee
Avoid unexpected concurrent access (#94)
In file {chardev,chardev2,sleep}.c, the variable to determine
the exclusive access was of integer type, which led to race
condition.

This patch rewrote the above with atomic CAS respectively
to eliminate the race.

Close #93
2021-09-07 23:42:06 +08:00
linD026
9289bfe59c
Fix the warnings raised by Sparse (#92)
Sparse[1] is a semantic parser, capable of finding out the potential
problems of Linux kernel code. This patch fixed the warnings.

[1] https://www.kernel.org/doc/html/latest/dev-tools/sparse.html
2021-09-04 17:53:29 +08:00
linD026
eef2bc4395
Enforce Linux kernel coding style (#88)
The only exception is to indent with four spaces rather than tabs
for sticking to compact layout of source listing.

Close #87
2021-09-02 15:15:07 +08:00
Jim Huang
10c7a9433a Apply editorial changes
This patch makes source listing shorter and more compact, that helps
when browsing.
2021-08-08 01:24:59 +08:00
Jim Huang
d43259c553 Drop the deprecated init_module() and cleanup_module() 2021-08-08 00:29:24 +08:00
Jim Huang
1ac7bacfb8 Shorten chardev 2021-08-07 18:29:39 +08:00
demonsome
50e9d9176f
chardev: Revise comment on device node (#23)
The device file create in this example is "chardev". 
So input command "sudo cat /dev/chardev" will get a valid message
"I already told you %d times Hello world!"
2021-07-31 23:03:16 +08:00
Jim Huang
64f791f274 Improve the compatibility with kernel version < 5.6 2021-07-22 07:17:31 +08:00
Jim Huang
50b8dfe6c2 Enforce the customized style for example code
Instead of using tab for indention, the style defaults to 4 spaces for
the sake of compact layout.
2021-07-22 06:58:13 +08:00
Jim Huang
2246e20809 Add LaTeX script and sample code 2021-07-22 06:35:24 +08:00