[PATCH 2/2] ext4: Fix zalloc()
Richard Weinberger
richard at nod.at
Tue Jul 2 21:42:23 CEST 2024
The zalloc() function suffers from two problems.
1. If memalign() fails it will return NULL and memset() will use a NULL pointer.
2. memalign() itself seems to crash when more than 2^32 bytes are requested.
So, check the return value of memalign() and allocate only of size is less than
CONFIG_SYS_MALLOC_LEN.
Signed-off-by: Richard Weinberger <richard at nod.at>
---
FWIW, I didn't investigate further why memalign() fails for large sizes.
Maybe this is an issue on it's own.
Thanks,
//richard
---
fs/ext4/ext4_common.h | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ext4_common.h b/fs/ext4/ext4_common.h
index 84500e990a..0d1f72ae01 100644
--- a/fs/ext4/ext4_common.h
+++ b/fs/ext4/ext4_common.h
@@ -43,8 +43,14 @@
static inline void *zalloc(size_t size)
{
- void *p = memalign(ARCH_DMA_MINALIGN, size);
- memset(p, 0, size);
+ void *p = NULL;
+
+ if (size < CONFIG_SYS_MALLOC_LEN)
+ p = memalign(ARCH_DMA_MINALIGN, size);
+
+ if (p)
+ memset(p, 0, size);
+
return p;
}
--
2.35.3
More information about the U-Boot
mailing list