A curated collection of Linux device driver examples covering kernel modules, character drivers, procfs, ioctl, polling, interrupts, PCI, USB, DMA, block drivers, network drivers, TTY, and more.
This repository provides hands-on Linux device driver examples designed for:
- Beginners learning Linux kernel programming
- Embedded Linux developers
- Device driver engineers
- Interview preparation
- Reference implementations for real projects
The examples progress from basic kernel modules to advanced driver development concepts.
32+ practical examples
Progressive learning structure
Linux kernel module development
Character driver implementation
procfs/sysfs examples
Interrupt handling
PCI & USB driver skeletons
DMA programming
Block device drivers
Network device drivers
TTY subsystem examples
Red-black tree implementation
Device-Driver-samples/
│
├── 0_index/
├── 1_Introduction_of_Linux_and_Device_Drivers/
├── 2_start_with_driver_development/
│
├── ex_1_hello_world/
├── ex_2_module_parameters/
├── ex_3_scull_basic/
├── ex_4_proc_fs_basic/
├── ex_5_proc_fs_iterator/
├── ex_6_completion/
├── ex_7_ioctl/
├── ex_8_pipe_sleep/
├── ex_9_pipe_sleep/
├── ex_10_polling/
├── ex_11_asynchronous_tech/
├── ex_12_seeking/
├── ex_13_jit/
├── ex_14_jiq/
├── ex_15_short_ioporting/
├── ex_16_short_port_brief/
├── ex_17_short_mmio/
├── ex_18_short_IRQ/
├── ex_19_short_IRQ_probe/
├── ex_20_pci_skel/
├── ex_21_usb_skel/
├── ex_22_lddbus/
├── ex_23_example/
├── ex_24_copy_zero/
├── ex_25_async_io/
├── ex_26_msi_interrupt/
├── ex_27_DMA/
├── ex_28_DMA_sg_/
├── ex_29_block_device/
├── ex_30_netdev/
├── ex_31_TTY/
├── ex_32_rbtree/
│
├── bin/
├── LICENSE
└── README.mdFollow examples in order:
| Example | Topic |
|---|---|
| ex_1 | Hello World Module |
| ex_2 | Module Parameters |
| ex_3 | SCULL Character Driver |
| ex_4 | Basic procfs |
| ex_5 | procfs Iterator |
| Example | Topic |
|---|---|
| ex_6 | Completion |
| ex_7 | IOCTL |
| ex_8 | Sleep & Wakeup |
| ex_10 | Polling |
| ex_11 | Async Notification |
| ex_12 | Seeking |
| ex_13 | JIT |
| ex_14 | JIQ |
| Example | Topic |
|---|---|
| ex_17 | MMIO |
| ex_18 | Interrupt Handling |
| ex_19 | IRQ Probe |
| ex_20 | PCI Skeleton |
| ex_21 | USB Skeleton |
| ex_26 | MSI Interrupts |
| ex_27 | DMA |
| ex_28 | Scatter-Gather DMA |
| Example | Topic |
|---|---|
| ex_29 | Block Device Driver |
| ex_30 | Network Device Driver |
| ex_31 | TTY Driver |
| ex_32 | Red-Black Tree |
- Linux Ubuntu 18.04+
- GCC 7+
- Make
- Kernel headers matching running kernel
- Root privileges
sudo apt update
sudo apt install build-essential linux-headers-$(uname -r)git clone https://github.com/jsramesh1990/Device-Driver-samples.git
cd Device-Driver-samplesExample:
cd ex_1_hello_world
makesudo insmod hello.koCheck logs:
dmesg | tailsudo rmmod helloflowchart LR
A[Write Driver Code] --> B[Build Module]
B --> C[Insert Module]
C --> D[Test Driver]
D --> E[Check dmesg Logs]
E --> F[Remove Module]
modinfo module.kolsmoddmesg -wls /dev- Kernel Modules
- Character Drivers
- procfs
- sysfs
- IOCTL
- Polling
- Async Notification
- Interrupt Handling
- MMIO
- PCI Drivers
- USB Drivers
- DMA
- MSI
- Block Drivers
- Network Drivers
- TTY Drivers
- Kernel Data Structures
uname -rEnsure headers match kernel.
Use:
sudo insmod module.kosudo rmmod module_nameRecommended resources:
- Linux Device Drivers (LDD3)
- Linux Kernel Documentation
- Kernel source tree documentation
Contributions are welcome.
Fork → Clone → Improve → Pull RequestLinux Kernel | Embedded Systems | Device Drivers
````