On Fri, 2018-06-29 at 10:30 +0300, Kalle Valo wrote: > Pkshih <pkshih@xxxxxxxxxxx> writes: > > > On Tue, 2018-05-29 at 08:18 +0300, Kalle Valo wrote: > >> <pkshih@xxxxxxxxxxx> writes: > >> > > > > Because C2H data is little endian order, the struct will look like > > struct foo { > > #ifdef __LITTLE_ENDIAN > > u8 bar:4; > > u8 koo:4; > > #else > > u8 koo:4; > > u8 bar:4; > > #endif > > } > > With u8 you don't need endian check, right? I would assume that with > both little and big endian bar and koo would be in the same place. I think u8 with bitfield would be different between little and big endian machines. > > Is this a linux convention? > > Earlier bitfields were disliked but nowadays they seem to be have become > more acceptable. But I think the preferred way still is something like > this (using u32 and 16 bit fields): > > struct foo { > __le32 koobar; > } > > #define RTLWIFI_BAR_MASK GENMASK(15, 0) > #define RTLWIFI_KOO_MASK GENMASK(31, 16) > > bar = FIELD_GET(RTLWIFI_BAR_MASK, __le32_to_cpu(foo->koobar)); > koo = FIELD_GET(RTLWIFI_KOO_MASK, __le32_to_cpu(foo->koobar)); > > Of course there can be other good ways to do the same, others can chime > in about those, but this is how I would do it. > I will rewrite this part by your suggestions. Thanks PK