LDD3 notes: Data types
My notes while reading Linux Device Drivers 3rd edition.
size_t vs ssize_t for negative values as error codes
C99 [u]intptr_t, integer which would fit a pointer. Not used in Linux. Similar to eCos cyg_addrword.
fixed size integers
- u8..s32 within kernel
- ioctl structures shared with userspace use prefix __u8
_t Typedefs
- for portability only
- out of fashion
- inconvenient printk use
Important constants: HZ. PAGE_SIZE/SHIFT
Endianness
- cpu_to_le32() .. be64_to_cpu()
Padding
- force struct to match hardware expectations, without padding for performance: __attribute__ ((packed))
Error codes in pointers
- ERR_PTR() -> IS_ERR() -> PTR_ERR()
Lists
- list_del_init() - re-init for future re-insertion
- list_for_each_entry() - foreach and list_entry combined
Comments
Post a Comment