Search Linux Wireless

Re: [PATCH 13/14] rtlwifi: access skb->data to get C2H data by macro

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/03/2018 05:57 AM, Kalle Valo wrote:
Felix Fietkau <nbd@xxxxxxxx> writes:

On 2018-07-03 08:14, Kalle Valo wrote:
Pkshih <pkshih@xxxxxxxxxxx> writes:

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.

To me that does not make any sense, I have never heard about bit
endianness any of the devices I have worked on.

Unfortunately, the order in which these fields are laid out is different
between big and little endian, even when only dealing with u8.

Oh, didn't know that. Can you give some examples about endian problems
with u8 bitfields? Still not getting it. Not that it matters, just
curious.

That alone is a strong reason to avoid bitfields entirely for anything
shared between the host and something else.

Very good to know, thanks.

Kalle,

By now, I think you understand that not only the byte order is different between BE and LE, but the bit order within a byte is different as well. In the normal situation where only byte-sized quantities are involved, then there need not be any concern. If you need to mask part of the byte, the mask itself will be in the correct endianess.

To me, the main advantage of using using bitfield notation is that the compiler does the work of generating the masks needed to extract a portion of the byte. I consider that to be slightly less likely to have errors that relying on the programmer to generate the mask. A secondary benefit is that the bitfield notation is self documenting.

Larry




[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Wireless Personal Area Network]     [Linux Bluetooth]     [Wireless Regulations]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]

  Powered by Linux