All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Walle <mwalle@kernel.org>
To: Huang Jianan <jnhuang95@gmail.com>, Tom Rini <trini@konsulko.com>
Cc: linux-erofs@lists.ozlabs.org, u-boot@lists.denx.de,
	Michael Walle <mwalle@kernel.org>
Subject: [PATCH 1/4] fs/erofs: align the malloc'ed data
Date: Mon, 23 Mar 2026 14:42:17 +0100	[thread overview]
Message-ID: <20260323134305.2675822-2-mwalle@kernel.org> (raw)
In-Reply-To: <20260323134305.2675822-1-mwalle@kernel.org>

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.

Signed-off-by: Michael Walle <mwalle@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, ...)	\
-- 
2.47.3



  reply	other threads:[~2026-03-23 13:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-23 13:42 [PATCH 0/4] fs/erofs: major alignment fixes Michael Walle
2026-03-23 13:42 ` Michael Walle [this message]
2026-03-23 14:41   ` [PATCH 1/4] fs/erofs: align the malloc'ed data Gao Xiang
2026-03-23 15:08     ` Michael Walle
2026-03-23 15:13       ` Gao Xiang
2026-03-23 13:42 ` [PATCH 2/4] fs/erofs: allocate data buffers on heap with alignment (1/3) Michael Walle
2026-03-23 13:42 ` [PATCH 3/4] fs/erofs: allocate data buffers on heap with alignment (2/3) Michael Walle
2026-03-23 13:42 ` [PATCH 4/4] fs/erofs: allocate data buffers on heap with alignment (3/3) Michael Walle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260323134305.2675822-2-mwalle@kernel.org \
    --to=mwalle@kernel.org \
    --cc=jnhuang95@gmail.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.