[PATCH 04/19] libext2fs: refactor aligned MMP buffer allocation

Darrick J. Wong
2025-11-06T22:32:09Z

Hoist the code that allocates an MMP buffer into a separate helper.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
lib/ext2fs/ext2fs.h | 1 +
debian/libext2fs2t64.symbols | 1 +
lib/ext2fs/dupfs.c | 5 +----
lib/ext2fs/mmp.c | 12 ++++++++----
4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index dec48b80d341db..c4fcb10bea0fb9 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1861,6 +1861,7 @@ errcode_t ext2fs_mmp_update(ext2_filsys fs);
errcode_t ext2fs_mmp_update2(ext2_filsys fs, int immediately);
errcode_t ext2fs_mmp_stop(ext2_filsys fs);
unsigned ext2fs_mmp_new_seq(void);
+errcode_t ext2fs_mmp_get_mem(ext2_filsys fs, void **ptr);

/* read_bb.c */
extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
diff --git a/debian/libext2fs2t64.symbols b/debian/libext2fs2t64.symbols
index 01f4f269a2660e..affe4c27d4e791 100644
--- a/debian/libext2fs2t64.symbols
+++ b/debian/libext2fs2t64.symbols
@@ -448,6 +448,7 @@ libext2fs.so.2 libext2fs2t64 #MINVER#
ext2fs_mmp_clear@Base 1.42
ext2fs_mmp_csum_set@Base 1.43
ext2fs_mmp_csum_verify@Base 1.43
+ ext2fs_mmp_get_mem@Base 1.47.4
ext2fs_mmp_init@Base 1.42
ext2fs_mmp_new_seq@Base 1.42
ext2fs_mmp_read@Base 1.42
diff --git a/lib/ext2fs/dupfs.c b/lib/ext2fs/dupfs.c
index 02721e1a574a1f..0fd4e6c67afb5d 100644
--- a/lib/ext2fs/dupfs.c
+++ b/lib/ext2fs/dupfs.c
@@ -104,10 +104,7 @@ errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest)
}
}
if (src->mmp_cmp) {
- int align = ext2fs_get_dio_alignment(src->mmp_fd);
-
- retval = ext2fs_get_memalign(src->blocksize, align,
- &fs->mmp_cmp);
+ retval = ext2fs_mmp_get_mem(src, &fs->mmp_cmp);
if (retval)
goto errout;
memcpy(fs->mmp_cmp, src->mmp_cmp, src->blocksize);
diff --git a/lib/ext2fs/mmp.c b/lib/ext2fs/mmp.c
index 6337852c3f6700..41ef4e3e2aa6c5 100644
--- a/lib/ext2fs/mmp.c
+++ b/lib/ext2fs/mmp.c
@@ -41,6 +41,13 @@
#endif
#endif

+errcode_t ext2fs_mmp_get_mem(ext2_filsys fs, void **ptr)
+{
+ int align = ext2fs_get_dio_alignment(fs->mmp_fd);
+
+ return ext2fs_get_memalign(fs->blocksize, align, ptr);
+}
+
errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
{
#ifdef CONFIG_MMP
@@ -78,10 +85,7 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
}

if (fs->mmp_cmp == NULL) {
- int align = ext2fs_get_dio_alignment(fs->mmp_fd);
-
- retval = ext2fs_get_memalign(fs->blocksize, align,
- &fs->mmp_cmp);
+ retval = ext2fs_mmp_get_mem(fs, &fs->mmp_cmp);
if (retval)
return retval;
}