Skip to content

Commit

Permalink
pkg/littlefs: fix unaligned memory access
Browse files Browse the repository at this point in the history
Previously `tests/pkg_littlefs` crashed on the `samr21-xpro`. This
now aligns the buffers in `littlefs_desc_t` to the alignment
requirement of `uint32_t`.
  • Loading branch information
maribu committed Aug 18, 2022
1 parent 2dd5923 commit 9c48bb1
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions sys/include/fs/littlefs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
#ifndef FS_LITTLEFS_FS_H
#define FS_LITTLEFS_FS_H

#ifdef __cplusplus
extern "C" {
#endif
#include <stdalign.h>

#include "vfs.h"
#include "lfs.h"
#include "mtd.h"
#include "mutex.h"


#ifdef __cplusplus
extern "C" {
#endif

/**
* @name littlefs configuration
* @{
Expand Down Expand Up @@ -82,18 +85,18 @@ typedef struct {
uint16_t sectors_per_block; /**< number of sectors per block */
#if LITTLEFS_FILE_BUFFER_SIZE || DOXYGEN
/** file buffer to use internally if LITTLEFS_FILE_BUFFER_SIZE is set */
uint8_t file_buf[LITTLEFS_FILE_BUFFER_SIZE];
alignas(uint32_t) uint8_t file_buf[LITTLEFS_FILE_BUFFER_SIZE];
#endif
#if LITTLEFS_READ_BUFFER_SIZE || DOXYGEN
/** read buffer to use internally if LITTLEFS_READ_BUFFER_SIZE is set */
uint8_t read_buf[LITTLEFS_READ_BUFFER_SIZE];
alignas(uint32_t) uint8_t read_buf[LITTLEFS_READ_BUFFER_SIZE];
#endif
#if LITTLEFS_PROG_BUFFER_SIZE || DOXYGEN
/** prog buffer to use internally if LITTLEFS_PROG_BUFFER_SIZE is set */
uint8_t prog_buf[LITTLEFS_PROG_BUFFER_SIZE];
alignas(uint32_t) uint8_t prog_buf[LITTLEFS_PROG_BUFFER_SIZE];
#endif
/** lookahead buffer to use internally */
uint8_t lookahead_buf[LITTLEFS_LOOKAHEAD_SIZE / 8];
alignas(uint32_t) uint8_t lookahead_buf[LITTLEFS_LOOKAHEAD_SIZE / 8];
} littlefs_desc_t;

/** The littlefs vfs driver */
Expand Down

0 comments on commit 9c48bb1

Please sign in to comment.