* [PATCH] block: don't error while flushing when write support is disabled
@ 2026-01-15 14:24 Enrico Jörns
2026-01-15 14:52 ` Ahmad Fatoum
2026-01-16 7:12 ` Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Enrico Jörns @ 2026-01-15 14:24 UTC (permalink / raw)
To: barebox; +Cc: 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.
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.
Signed-off-by: Enrico Jörns <ejo@pengutronix.de>
---
common/block.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/common/block.c b/common/block.c
index ca2ed37dbd..abd05eab39 100644
--- a/common/block.c
+++ b/common/block.c
@@ -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)
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block: don't error while flushing when write support is disabled
2026-01-15 14:24 [PATCH] block: don't error while flushing when write support is disabled Enrico Jörns
@ 2026-01-15 14:52 ` Ahmad Fatoum
2026-01-16 7:12 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2026-01-15 14:52 UTC (permalink / raw)
To: Enrico Jörns, barebox
On 1/15/26 3:24 PM, Enrico Jörns wrote:
> 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.
>
> Signed-off-by: Enrico Jörns <ejo@pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Thanks,
Ahmad
> ---
> common/block.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/common/block.c b/common/block.c
> index ca2ed37dbd..abd05eab39 100644
> --- a/common/block.c
> +++ b/common/block.c
> @@ -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)
--
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 |
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] block: don't error while flushing when write support is disabled
2026-01-15 14:24 [PATCH] block: don't error while flushing when write support is disabled Enrico Jörns
2026-01-15 14:52 ` Ahmad Fatoum
@ 2026-01-16 7:12 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2026-01-16 7:12 UTC (permalink / raw)
To: barebox, Enrico Jörns
On Thu, 15 Jan 2026 15:24:01 +0100, Enrico Jörns wrote:
> 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,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-16 7:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-15 14:24 [PATCH] block: don't error while flushing when write support is disabled Enrico Jörns
2026-01-15 14:52 ` Ahmad Fatoum
2026-01-16 7:12 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox