[Concept,v2,07/30] blkmap: Handle read-only slices in write path

Message ID 20260102005112.552256-8-sjg@u-boot.org
State New
Headers
Series ext4l: Add write support (part L) |

Commit Message

Simon Glass Jan. 2, 2026, 12:50 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Some blkmap slices (like blkmap_crypt) don't support writes and have
their write function set to NULL. The blkmap_blk_write_slice() function
calls the write function without checking if it's NULL, causing a crash
when attempting to write to such slices.

Add a NULL check before calling the write function. When the slice
doesn't support writes, return 0 to indicate no blocks were written.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

(no changes since v1)

 drivers/block/blkmap.c | 3 +++
 1 file changed, 3 insertions(+)
  

Patch

diff --git a/drivers/block/blkmap.c b/drivers/block/blkmap.c
index 14aa1e4d088..bd55bdf24b7 100644
--- a/drivers/block/blkmap.c
+++ b/drivers/block/blkmap.c
@@ -281,6 +281,9 @@  static ulong blkmap_blk_write_slice(struct blkmap *bm, struct blkmap_slice *bms,
 {
 	lbaint_t nr, cnt;
 
+	if (!bms->write)
+		return 0;
+
 	nr = blknr - bms->blknr;
 	cnt = (blkcnt < bms->blkcnt) ? blkcnt : bms->blkcnt;
 	return bms->write(bm, bms, nr, cnt, buffer);