Skip to content

Commit

Permalink
Relaxed alignment requirements for lfs_malloc
Browse files Browse the repository at this point in the history
The only reason we needed this alignment was for the lookahead buffer.

Now that the lookahead buffer is relaxed to operate on bytes, we can
relax our malloc alignment requirement all the way down to the byte
level, since we mainly use lfs_malloc to allocate byte-level buffers.

This does introduce a risk that we might need word-level mallocs in the
future. If that happens we will need to decide if changing the malloc
alignment is a breaking change, or gate alignment requirements behind
user provided defines.

Found by HiFiPhile.
  • Loading branch information
geky committed Jan 16, 2024
1 parent b1b10c0 commit 6056767
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lfs_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ static inline uint32_t lfs_tobe32(uint32_t a) {
uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size);

// Allocate memory, only used if buffers are not provided to littlefs
// Note, memory must be 64-bit aligned
//
// littlefs current has no alignment requirements, as it only allocates
// byte-level buffers.
static inline void *lfs_malloc(size_t size) {
#ifndef LFS_NO_MALLOC
return malloc(size);
Expand Down

0 comments on commit 6056767

Please sign in to comment.