Improve example in 15.2 Work queues with error handling and cleanup #317
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since the example in Chapter 15.2 demonstrates the use of work queues in kernel modules, improving its reliability with proper error handling and cleanup logic helps reflect best practices in modern kernel development. This change enhances safety by preventing null pointer dereference during allocation failure and ensuring all work is completed before module unload.
Summary by Bito
This pull request improves the example in Chapter 15.2, "Work queues", by adding error handling for alloc_workqueue() and ensuring flush_workqueue() is called before destroy_workqueue() in the module exit path. These changes align the code with kernel best practices, prevent common pitfalls like null pointer dereference, and make the example safer for readers and learners on modern kernels.
These changes improve robustness in the workqueue lifecycle and reduce the risk of memory corruption.
Unit_tests added : False
** Estimated effort to review (1-5, lower is better)** : 2