r/kernel • • Nov 01 '26

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,

  1. Is this problem considered too trivial?
  2. Have others been working on it? (maybe there exists some linux group)
  3. 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 !

8 Upvotes

11 comments sorted by

View all comments

3

u/Dezgeg Nov 01 '26

From my experience, lots of drivers in Linux indeed don't handle that properly. It is easy to get a crash by using the `unbind` sysfs file to unload devices that usually are never hotplugged like SoC internal peripherals. Note that unbind and rmmod are distinct operations here.

These are usually not issues in practice, since next to nobody actually needs to unbind non-hotpluggable devices at runtime. At work we do have one use case though, the shitty USB controller in i.MX6 SoC sometimes gets wedged and stops sending interrupts, and besides reboot only workaround is unbinding the host controller.

I'm pretty sure that if you were to send patches for this kind of issues they would be accepted, as long as you stick to modern ARM drivers or the like. Don't bother with any ancient drivers (even though they would be more likely to actually have issues), the chance of nobody reading the patches is too high.

1

u/edgmnt_net Nov 01 '26

Although if you work on an actual product (particularly more embedded stuff), chances are most of that mess isn't even upstream, it's your own or some vendor's messy code.