Skip to content

Commit

Permalink
pkg/littlefs2: fix unaligned memory access
Browse files Browse the repository at this point in the history
Previously `tests/pkg_littlefs2` crashed on the `samr21-xpro`. This
now aligns the buffers in `littlefs2_desc_t` to the alignment
requirement of `uint32_t`.
  • Loading branch information
maribu committed Aug 18, 2022
1 parent 9c48bb1 commit b48fe8b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions sys/include/fs/littlefs2_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
#ifndef FS_LITTLEFS2_FS_H
#define FS_LITTLEFS2_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
* @ingroup config
Expand Down Expand Up @@ -99,20 +101,20 @@ typedef struct {
#if CONFIG_LITTLEFS2_FILE_BUFFER_SIZE || DOXYGEN
/** file buffer to use internally if CONFIG_LITTLEFS2_FILE_BUFFER_SIZE
* is set */
uint8_t file_buf[CONFIG_LITTLEFS2_FILE_BUFFER_SIZE];
alignas(uint32_t) uint8_t file_buf[CONFIG_LITTLEFS2_FILE_BUFFER_SIZE];
#endif
#if CONFIG_LITTLEFS2_READ_BUFFER_SIZE || DOXYGEN
/** read buffer to use internally if CONFIG_LITTLEFS2_READ_BUFFER_SIZE
* is set */
uint8_t read_buf[CONFIG_LITTLEFS2_READ_BUFFER_SIZE];
alignas(uint32_t) uint8_t read_buf[CONFIG_LITTLEFS2_READ_BUFFER_SIZE];
#endif
#if CONFIG_LITTLEFS2_PROG_BUFFER_SIZE || DOXYGEN
/** prog buffer to use internally if CONFIG_LITTLEFS2_PROG_BUFFER_SIZE
* is set */
uint8_t prog_buf[CONFIG_LITTLEFS2_PROG_BUFFER_SIZE];
alignas(uint32_t) uint8_t prog_buf[CONFIG_LITTLEFS2_PROG_BUFFER_SIZE];
#endif
/** lookahead buffer to use internally */
uint8_t lookahead_buf[CONFIG_LITTLEFS2_LOOKAHEAD_SIZE];
alignas(uint32_t) uint8_t lookahead_buf[CONFIG_LITTLEFS2_LOOKAHEAD_SIZE];
} littlefs2_desc_t;

/** The littlefs vfs driver */
Expand Down

0 comments on commit b48fe8b

Please sign in to comment.