[PATCH 1/4] fs/erofs: align the malloc'ed data

Gao Xiang hsiangkao at linux.alibaba.com
Tue Mar 24 01:41:35 AEDT 2026


Hi Michael,

On 2026/3/23 21:42, Michael Walle wrote:
> The data buffers are used to transfer from or to hardware peripherals.
> Often, there are restrictions on addresses, i.e. they have to be aligned
> at a certain size. Thus, allocate the data on the heap instead of the
> stack (at a random address alignment). Use malloc_cache_aligned() to get
> an aligned buffer.

Many thanks for the patch, I wonder if it's possible to
submit the patches to erofs-utils first (even make
malloc_cache_aligned() as another malloc() for example)?

Since I'd like to make u-boot codebase following
erofs-utils, but I don't think Jianan have the
bandwidth now, but if you have some use cases,
you could help syncing up a bit.

Or at least, let's keep these four patches in sync
between erofs-utils and u-boot.

Many thanks!
Gao Xiang

> 
> Signed-off-by: Michael Walle <mwalle at kernel.org>
> ---
>   fs/erofs/data.c     | 11 ++++-------
>   fs/erofs/internal.h |  1 +
>   2 files changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/erofs/data.c b/fs/erofs/data.c
> index b58ec6fcc66..61dbae51a9a 100644
> --- a/fs/erofs/data.c
> +++ b/fs/erofs/data.c
> @@ -319,15 +319,13 @@ static int z_erofs_read_data(struct erofs_inode *inode, char *buffer,
>   		}
>   
>   		if (map.m_plen > bufsize) {
> -			char *tmp;
> -
>   			bufsize = map.m_plen;
> -			tmp = realloc(raw, bufsize);
> -			if (!tmp) {
> +			free(raw);
> +			raw = malloc_cache_aligned(bufsize);
> +			if (!raw) {
>   				ret = -ENOMEM;
>   				break;
>   			}
> -			raw = tmp;
>   		}
>   
>   		ret = z_erofs_read_one_data(inode, &map, raw,
> @@ -336,8 +334,7 @@ static int z_erofs_read_data(struct erofs_inode *inode, char *buffer,
>   		if (ret < 0)
>   			break;
>   	}
> -	if (raw)
> -		free(raw);
> +	free(raw);
>   	return ret < 0 ? ret : 0;
>   }
>   
> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
> index 1875f37fcd2..13c862325a6 100644
> --- a/fs/erofs/internal.h
> +++ b/fs/erofs/internal.h
> @@ -11,6 +11,7 @@
>   #include <linux/printk.h>
>   #include <linux/log2.h>
>   #include <inttypes.h>
> +#include <memalign.h>
>   #include "erofs_fs.h"
>   
>   #define erofs_err(fmt, ...)	\



More information about the Linux-erofs mailing list