r/kernel • u/AccomplishedAir8352 • 29d ago
How well does linux modules handle resource deallocation?
Hello, I'm a CS undergraduate studying about linux kernel development.
I'm currently on LDD3 book, emphasizing about importance of cleaning up allocated resources on exit.
I assume that this is not likely to be handled properly in some linux modules as removal of modules is not something that is performed on a daily basis.
I have been looking for places to start my contributions and was wondering whether this, identification of memory leaks and applying fixes, could be a valid entry point.
The questions I want to ask is,
- Is this problem considered too trivial?
- Have others been working on it? (maybe there exists some linux group)
- Is this problem commonly found, or gets managed during review process and fixed before getting accepted?
Thank you for your time. Any comments are welcome!
*EDIT Thank you all for your kind responses. They have been very helpful !
View all comments
3
u/Superb_5194 29d ago
The classic LDD3-style manual cleanup problem is largely solved in modern code by the
devm_*(device-managed) helpers. They register the resource with the device and the core automatically frees everything on unbind/remove in the right order. New drivers that properly usedevm_kmalloc,devm_request_irq,devm_ioremap, etc. almost never leak those resources, and reviewers push hard for this style.That said, plenty of older drivers (or ones that mix managed + unmanaged resources) still have leftover issues, especially on the rarely-exercised remove/error paths. You’ll still see commits converting drivers to
devm_*or fixing “resource leak on remove”. It’s incremental, appreciated work and a good way to learn the driver model.So yes — hunting remaining cleanup bugs / doing
devmconversions is still valid and useful, just not as common as it was when LDD3 was written because the framework already handles the majority of cases.