Skip to contentSkip to conversation

lib: sparse: fix raw chunk bounce buffer size with large blocks

PATCH New David Lechner 1 participant 1 message Nov 18 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: sparse: fix raw chunk bounce buffer size with large blocks

Limit the bounce buffer for raw chunks to 8 MiB instead of FASTBOOT_MAX_BLK_WRITE blocks. That is the same with 512-byte blocks, but 64 MiB with the 4 KiB blocks of UFS, which is too much to allocate with a small heap.

Fixes b1aade87ca1f ("lib: sparse: allocate FASTBOOT_MAX_BLK_WRITE instead of small number")
---
 lib/image-sparse.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/image-sparse.c +4 -1
index 48e5d8ee869..bbcae433f20 100644
@@ -46,6 +46,8 @@
 
 #include <linux/math64.h>
 #include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/sizes.h>
 
 static void default_log(const char *ignored, char *response) {}
 
@@ -55,7 +57,8 @@ static lbaint_t write_sparse_chunk_raw(struct sparse_storage *info,
 				       char *response)
 {
 	lbaint_t n = blkcnt, write_blks, blks = 0;
-	lbaint_t aligned_buf_blks = FASTBOOT_MAX_BLK_WRITE;
+	lbaint_t aligned_buf_blks = min_t(lbaint_t, FASTBOOT_MAX_BLK_WRITE,
+					  SZ_8M / info->blksz);
 	uint32_t *aligned_buf = NULL;
 
 	if (CONFIG_IS_ENABLED(SYS_DCACHE_OFF)) {

---
base-commit: 6201222134cd704b5717211fc917e2ca6263577a
base-tree: https://git.u-boot-project.org/u-boot/u-boot.git next
change-id: 20261117-sparse-bounce-buffer-size-b26032a7417c

Best regards,

Signature · 1 line
David Lechner <[email protected]>