Skip to contentSkip to conversation

block: don't error while flushing when write support is disabled

PATCH Applied Enrico Jörns 3 participants 3 messages Jan 15 – Jan 16

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: don't error while flushing when write support is disabled

If write support for the underlying device is disabled (e.g. by disabling CONFIG_MCI_WRITE), blk->ops->write will be NULL. Unconditionally dereferencing/calling blk->ops->write() results in a NULL pointer dereference.

Fix this by making chunk_flush() a noop for missing write support. Don't return an error since there should be nothing to flush if write support is disabled, anyway.

Note that barebox currently does not prevent calling write/flush operations, even if CONFIG_MCI_WRITE and thus write support is actually disabled.
But this should be handled on another level.

---
 common/block.c | 3 +++
 1 file changed, 3 insertions(+)
common/block.c +3 -0
index ca2ed37dbd..abd05eab39 100644
@@ -60,6 +60,9 @@ static int chunk_flush(struct block_device *blk, struct chunk *chunk)
 	if (!chunk->dirty)
 		return 0;
 
+	if (!blk->ops->write)
+		return 0;
+
 	len = writebuffer_io_len(blk, chunk);
 	ret = blk->ops->write(blk, chunk->data, chunk->block_start, len);
 	if (ret < 0)
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Enrico Jörns

If write support for the underlying device is disabled (e.g. by disabling CONFIG_MCI_WRITE), blk->ops->write will be NULL. Unconditionally dereferencing/calling blk->ops->write() results in a NULL pointer dereference.

Fix this by making chunk_flush() a noop for missing write support. Don't return an error since there should be nothing to flush if write support is disabled, anyway.

Quoted 6 lines

Note that barebox currently does not prevent calling write/flush operations, even if CONFIG_MCI_WRITE and thus write support is actually disabled.
But this should be handled on another level.

Thanks,
Ahmad

Quoted 18 lines
---
 common/block.c | 3 +++
 1 file changed, 3 insertions(+)
common/block.c +3 -0
index ca2ed37dbd..abd05eab39 100644
@@ -60,6 +60,9 @@ static int chunk_flush(struct block_device *blk, struct chunk *chunk)
 	if (!chunk->dirty)
 		return 0;
 
+	if (!blk->ops->write)
+		return 0;
+
 	len = writebuffer_io_len(blk, chunk);
 	ret = blk->ops->write(blk, chunk->data, chunk->block_start, len);
 	if (ret < 0)
Signature · 4 lines
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |
Applied
#2 lore raw
In reply to Enrico Jörns
Quoted 10 lines · Enrico Jörns

If write support for the underlying device is disabled (e.g. by disabling CONFIG_MCI_WRITE), blk->ops->write will be NULL. Unconditionally dereferencing/calling blk->ops->write() results in a NULL pointer dereference.

Fix this by making chunk_flush() a noop for missing write support. Don't return an error since there should be nothing to flush if write support is disabled, anyway.

[...]

Applied, thanks!

[1/1] block: don't error while flushing when write support is disabled
https://git.pengutronix.de/cgit/barebox/commit/?id=ddeff3d01e3d (link may not be stable)

Best regards,

Signature · 1 line
Sascha Hauer <[email protected]>