From 0d902c8c54bbc36f24b40c49eb9872aa75b779e4 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Wed, 9 Feb 2011 09:30:09 +0000 Subject: Buffering should align itself and not rely on buffering_reset parameters when storage alignment matters so that wrapped reads maintain alignment. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29258 a1c6a512-1295-4272-9138-f99709370657 --- apps/buffering.c | 5 +++++ firmware/export/system.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/apps/buffering.c b/apps/buffering.c index e37b053881..123c7bc85f 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -1572,6 +1572,11 @@ void buffering_init(void) /* Initialise the buffering subsystem */ bool buffering_reset(char *buf, size_t buflen) { + /* Wraps of storage-aligned data must also be storage aligned, + thus buf and buflen must be a aligned to an integer multiple of + the storage alignment */ + STORAGE_ALIGN_BUFFER(buf, buflen); + if (!buf || !buflen) return false; diff --git a/firmware/export/system.h b/firmware/export/system.h index 65db721bb4..78bddae387 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h @@ -388,11 +388,14 @@ static inline void cpucache_flush(void) #define STORAGE_PAD(x) ((x) + CACHEALIGN_SIZE - 1) /* Number of bytes in the last cacheline assuming buffer of size x is aligned */ #define STORAGE_OVERLAP(x) ((x) & (CACHEALIGN_SIZE - 1)) + #define STORAGE_ALIGN_BUFFER(start, size) \ + ALIGN_BUFFER((start), (size), CACHEALIGN_SIZE) #else #define STORAGE_ALIGN_ATTR #define STORAGE_ALIGN_DOWN(x) (x) #define STORAGE_PAD(x) (x) #define STORAGE_OVERLAP(x) 0 + #define STORAGE_ALIGN_BUFFER(start, size) #endif /* Double-cast to avoid 'dereferencing type-punned pointer will -- cgit v1.2.3