Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/{littlefs,littlefs2}: fix unaligned memory accesses #18473

Merged
merged 2 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 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 @@ -95,24 +97,24 @@ typedef struct {
* total number of block is defined in @p config.
* if set to 0, the total number of sectors from the mtd is used */
uint32_t base_addr;
uint16_t sectors_per_block; /**< number of sectors per block */
#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];
uint16_t sectors_per_block; /**< number of sectors per block */
} littlefs2_desc_t;

/** The littlefs vfs driver */
Expand Down
19 changes: 11 additions & 8 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 @@ -79,21 +82,21 @@ typedef struct {
* total number of block is defined in @p config.
* if set to 0, the total number of sectors from the mtd is used */
uint32_t base_addr;
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];
uint16_t sectors_per_block; /**< number of sectors per block */
} littlefs_desc_t;

/** The littlefs vfs driver */
Expand Down