Linux kernel design patterns - part 2
Posted Jun 16, 2009 10:13 UTC (Tue) by
johill (subscriber, #25196)
In reply to:
Linux kernel design patterns - part 2 by neilbrown
Parent article:
Linux kernel design patterns - part 2
Yes, I don't think you could possibly be aware of all patterns used. And it may well be possible that I brought this "partial exposure pattern" to the kernel myself, I've used it across the wireless code a lot but I don't know whether it is used elsewhere.
As for comparing, let me start with a very short comparison to the "expose everything" pattern:
Pros:
- users forced to use APIs, less potential for abuse & "trickery"
- internal details can be changed at will
Cons:
- not possible to embed into anything, needs to be allocated by API function
- cannot be allocated on stack
Other differences:
- no "init" function/macro necessary, but "alloc" function contains "init".
For the cases where I've done it this way, the fact that it cannot be embedded or on the stack is not important because it serves more as the container itself rather than being a helper that can be embedded into something else. The one exception could be rfkill, but I made that completely opaque because it had been abused so much in the past.
(
Log in to post comments)