[HAIFUX LECTURE] Managed Resource Allocation in Linux Device Drivers -- Eli Billauer
Eli Billauer
eli at billauer.co.il
Sat May 24 20:31:45 IDT 2014
On Monday, May 26th at 18:30, Haifux will gather to hear a talk by Eli
Billauer:
The Right Way: Managed Resource Allocation in Linux Device Drivers
Download the slides: http://www.haifux.org/lectures/323/haifux-devres.pdf
Abstract
Linux device drivers typically call kmalloc(), request_mem_region(),
ioremap() and other kernel API functions to obtain resources. Failing to
release them correctly when the device is removed leads to resource
leaks and possibly oopses. Even worse, if the initialization fails in
the middle, the allocation must be unrolled, which is typically done
with goto statements which are bug-prone.
The Device Managed Resources (devres, devm) API was added to the kernel
in 2007 (2.6.21) to solve this problem: The driver is only required to
use special functions to allocate its resources, but not to release
them. The kernel is responsible to free the resources when the device is
removed or if it fails to initialize. This doesn’t just make the code
shorter, but ensures that the removal of the device takes place correctly.
This method makes so much sense, that it isn’t clear how it’s not
mandatory. In fact, many essential allocation function don’t have a
managed counterpart in the kernel, which shows that this issue is quite
neglected.
Aside from preaching, this talk will focus on showing code snippets and
examples to clarify how this works. Subjects to be covered include
* How to use managed resources
* How to free managed resources manually, in particular unrolling a
partial initialization sequence (”Undo”)
* How to add custom function callbacks for specific rollback tasks
* How to write a custom managed resource allocator
* (maybe) The special functions for PCI
=================================================================
We meet in Taub building, room 6. For instructions see:
http://www.haifux.org/where.html
Attendance is free, and you are all invited!
==================================================================
Future lectures:
There are no scheduled lectures.
==================================================================
We are always interested in hearing your talks and ideas. If you wish to
give a talk, hold a discussion, or just plan some event haifux might be
interested in, please contact us at webmaster at haifux.org
--
Web: http://www.billauer.co.il
More information about the Linux-il
mailing list