summaryrefslogtreecommitdiffstats
path: root/include/linux/bitops.h
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-09-11 17:24:30 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-09-26 12:57:07 +0200
commit868294584575e7e1a783f4c962719ee0a052d6a5 (patch)
treead8ebebef710a49e4f29b778c6f2c55725332f71 /include/linux/bitops.h
parent5ea5aef53b9c2205f2af439bb6ac640871794288 (diff)
downloadbarebox-868294584575e7e1a783f4c962719ee0a052d6a5.tar.gz
barebox-868294584575e7e1a783f4c962719ee0a052d6a5.tar.xz
tlsf: give malloc 8-byte alignment on 32-bit as well
The current alignment of 4 bytes is too low. Access to 64-bit data via ldrd/strd requires at least an eight byte alignment: | Prior to ARMv6, if the memory address is not 64-bit aligned, the | data read from memory is UNPREDICTABLE. Alignment checking (taking | a data abort), and support for a big-endian (BE-32) data format are | implementation options. We already have at least an 8 byte alignment for dlmalloc, so have TLSF follow suit by aligning the accounting structures appropriately. Instead of adding manual padding, we could also enlarge block_header_t::size to an uint64_t unconditionally, but mark block_header_t __packed. This comes with a runtime cost though or ugly __builtin_assume_aligned annotations, so we stick to the simpler version. Reported-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de> Link: https://lore.barebox.org/barebox/ly7d1z1qvs.fsf@ensc-pc.intern.sigma-chemnitz.de/ Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20230911152433.3640781-5-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/linux/bitops.h')
-rw-r--r--include/linux/bitops.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index a5f6ac6545..b0d6ca6ac8 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -19,6 +19,7 @@
#define BITS_TO_U64(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(u64))
#define BITS_TO_U32(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(u32))
#define BITS_TO_BYTES(nr) DIV_ROUND_UP(nr, BITS_PER_TYPE(char))
+#define BYTES_TO_BITS(nb) (((BITS_PER_LONG * (nb)) / sizeof(long)))
#endif
/*