Use GPIO to control LED on/off and add related GPIO knowledge.
Test detail:
- Tested on Raspberry Pi 5B with Raspberry Pi OS (Debian 12, Linux
version 6.12.1-v8-16k+)
- Verify that LED example compiles and loads successfully
- Verify that LED turns on and off sucessfully
Since commit 0edb555 ("platform: Make platform_driver::remove() return
void"), the original `platform_driver::remove()` function returned an
integer value, usually an error code. This made driver developers think
that errors were properly handled. However, the driver core does not
stop the device removal process based on the error code, so the error
code did not serve its intended purpose. Therefore, the return type was
changed to `void` to avoid potential issues.
Make the devicemodel example run successfully on Linux v6.11+.
Testing detail:
- Tested on Raspberry Pi 5B with Raspberry Pi OS (Debian 12, Linux
version 6.12.1-v8-16k+)
- Verified the devicemodel examples compile and load successfully
Since the commit dbcedec ("gpiolib: legacy: Remove unused
gpio_request_array() and gpio_free_array()"), these functions had no
users in kernel and were subsequently removed to simplify the library.
These functions have been removed from GPIO examples for Linux
v6.10+ to ensure compatibility across all kernel versions.
Testing detail:
- Tested on Raspberry Pi 5B with Raspberry Pi OS (Debian 12, Linux
version 6.12.1-v8-16k+)
- Verified the GPIO examples compile and load successfully
- Verified GPIO17 interrupt turns on the LED (GPIO4)
- Verified GPIO18 interrupt turns off the LED (GPIO4)
Close#285
In cat_nonblock.c, function call of close() is missing, which could
lead to resource leak. Besides, using EXIT_FAILURE macro defined in
stdlib.h provides better readability.
Previously, the code did not call kobject_put when sysfs_create_file
failed, leading to a potential memory leak. This commit adds the missing
kobject_put to ensure proper resource cleanup.
In the export_store function, the error handling paths followed a
successful vinput_alloc_vdevice call are missing a corresponding
input_free_device call. Since vinput_alloc_vdevice internally calls
input_allocate_device, and input_register_device has not been called
yet, input_free_device should be used to properly free the allocated
input_device struct in this scenario[1].
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/input/input.c#n2094
In the export_store function, when vinput_register_vdevice fails, the
current error handling process calls device_unregister followed by
vinput_destroy_vdevice. However, the device_unregister here triggers its
release function, which already includes a call to
vinput_destroy_vdevice. As a result, vinput_destroy_vdevice is called
twice. Since vinput_destroy_vdevice contains module_put, this double
call must be avoided to prevent potential reference count issues.
After class_register failure, the wrong function class_unregister was
used. The correct cleanup function should be unregister_chrdev, as
register_chrdev was used before class_register.
The function pointer type of myvariable_store was incompatible with the
store member of struct kobj_attribute, leading to a compilation error
when the type conversion (void *) was omitted. This patch corrects the
function declaration and eliminates the need for type conversion.
As myvariable is declared as an integer, it is meaningless that putting
u after %d in the format specifier of sscanf for scanning an integer.
This patch removes the u in the format specifier for avoiding
misleading.
The procfile_write prints the content what user writes into. However,
when the content size is greater than or equal to PROCFS_MAX_SIZE,
procfile_write will print nothing, because the index for appending the
tail NULL character will be modulo to 0, which is an off-by-one error.
This fixes the problem by changing the upper bound of procfs_buffer_size
to (PROCFS_MAX_SIZE - 1), leaving one byte for NULL character. After
the change, we can discard the modulo because the range of
procfs_buffer_size is already between 0 and (PROCFS_MAX_SIZE - 1).
There is a subtle bug that if the atomic flag changes
between the time it was checked and the second time
it was checked, sleep.c would potentially block a
process that had specified O_NONBLOCK. This fixes
the bug by using atomic_cmpxchg instead of atomic_read.
For x86 architecture, the system call table cannot be used to invoke
a system call after commit 1e3ad78 since v6.9. This commit has been
backported to long term stable kernels, like v5.15.154+, v6.1.85+,
v6.6.26+ and v6.8.5+[1]. In this case, thanks to Kprobes, a hook can be
used instead on the system call entry to intercept the system call.
[1] https://stackoverflow.com/a/78607015
Co-authored-by: Hao Dong <hao.dong.work@outlook.com>
Add sudo to commands in Chapter 8 for example module interaction.
The "myvariables" in the module are set with 0660 permissions
via __ATTR(), preventing direct user access.
Options to fix this:
1. Instruct users to use 'sudo' to read/write files.
2. Relax the permission settings to 0666.
This commit adopts the sudo method to maintain security constraints.