Thread (33 messages) 33 messages, 4 authors, 2021-01-12

Re: [net-next 15/19] can: tcan4x5x: rework SPI access

From: Jakub Kicinski <kuba@kernel.org>
Date: 2021-01-08 16:33:29
Also in: linux-can

On Fri, 8 Jan 2021 11:07:26 +0100 Ahmad Fatoum wrote:
quoted
quoted
quoted
+struct __packed tcan4x5x_map_buf { 
+	struct tcan4x5x_buf_cmd cmd; 
+	u8 data[256 * sizeof(u32)]; 
+} ____cacheline_aligned;     
Due to the packing of the struct tcan4x5x_buf_cmd it should have a length of 4
bytes. Without __packed, will the "u8 data" come directly after the cmd?  
Yup, u8 with no alignment attribute will follow the previous
field with no holes.  
__packed has a documentation benefit though. It documents that the author
considers the current layout to be the only correct one. (and thus extra
care should be taken when modifying it).
____cacheline_aligned adds a big architecture dependent padding at the
end of this struct, so the size of this structure is architecture
dependent. Besides using packed forced the compiler to use byte by byte
loads on architectures without unaligned access, so __packed is not
free.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help