Sample code from http://appusajeev.wordpress.com/2011/06/18/writing-a-linux-character-device-driver/