Tag: TIL

  • TIL: private data struct in Linux kernel

    在 Linux kernel 當中有許多的 common struct,例如說 ieee80211_txq 這樣的結構,透過這樣的方式,可以讓不同的 driver 重用相同的 struct。但是,針對每個不同的 driver,還是會有不同的 private data,這時候就會用 private data struct 的方式來處理。 例如說,struct ieee80211_txq 是 mac80211 中的 intermediate tx queue,目前有使用的 wireless driver 為 ath9k, ath10k 以及 mt76。struct ieee80211_txq 的整個結構為: /** * struct ieee80211_txq – Software intermediate tx queue * * @vif: &struct ieee80211_vif pointer from the add_interface callback. * @sta: station table…

  • TIL: ARRAY_SIZE in Linux kernel

    from net/mac80211/sta_info.c, define at include/linux/kernel.h /** * ARRAY_SIZE – get the number of elements in array @arr * @arr: array to be sized */ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) __must_be_array: 檢查 a 是否為 array,當 a 為 array 時,會因為 &(a)[0] 變成 pointer,而讓 __same_type 產生 0 的結果,反之如果 a 為 pointer,因為 &(a)[0] 仍然是 pointer, __same_type 回傳…

  • TIL: ALIGN in Linux kernel

    from include/uapi/linux/kernel.h and scripts/dtc/dtc.h #define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))a – 1) #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) or #define ALIGN(x, a) (((x) + (a) – 1) & ~((a) – 1))