Close

Some good example code

A project log for /dev/analog0

Primitive analog output device for a Raspberry Pi.

Steven ClarkSteven Clark 04/28/2016 at 03:090 Comments

I've been reading through the Oreilly drivers book and thought I needed to see an example kernel module to get a sense for how it's done in practice. So I went into the kernel source tree to try to find a simple character device driver I could look at. These are located in drivers/char/ in a linux source tree. A few problems quickly presented themselves:

1. Nobody comments. Okay there are comments but they're mostly the bare minimum so you know who wrote the thing and what it's supposed to be. I know you aren't supposed to comment anything obvious but these files don't even have functions labeled by purpose.

2. Most of them only look slightly like the code in the book. The coder who wrote them went and changed the name of everything to something specific and none too clear. Usually you're lucky if you can identify the init and exit functions.

There seems to be at least one exception to 2: linux/drivers/char/raw.c Sure the comments are still pretty dire, but I can actually see the structure of this one, where the file operation functions are, where their pointers are loaded into a structure and a character device gotten from the system. I'm now at least significantly less concerned that I won't figure any of this out before the deadline.


I do kinda wish I wasn't the most experienced (only) person on the team now though. Having an interactive person to explain this would be much nicer than the book.

Discussions