[PATCH 03/13] block: propagate errors from blockdevice_unregister()
Sascha Hauer
s.hauer at pengutronix.de
Mon Aug 31 06:20:10 PDT 2026
blockdevice_unregister() discards the return value of devfs_remove() and
always reports success. A caller therefore has no way to find out that
the block device is still in use and goes on to free the memory the
cdev, and possibly its partitions, still refer to.
Return the error and do so before anything has been torn down, so the
caller can simply try again later. The buffer chunks and the block
device list entry stay untouched in that case.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Assisted-by: Claude:claude-opus-5
---
common/block.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/common/block.c b/common/block.c
index 5f509bfb9d..141604eb87 100644
--- a/common/block.c
+++ b/common/block.c
@@ -519,6 +519,15 @@ int blockdevice_register(struct block_device *blk)
int blockdevice_unregister(struct block_device *blk)
{
struct chunk *chunk, *tmp;
+ int ret;
+
+ /*
+ * Do this first: once the cdev is gone there is no way for the
+ * caller to retry, so give up while everything is still intact.
+ */
+ ret = devfs_remove(&blk->cdev);
+ if (ret)
+ return ret;
writebuffer_flush(blk);
@@ -532,7 +541,6 @@ int blockdevice_unregister(struct block_device *blk)
free(chunk);
}
- devfs_remove(&blk->cdev);
list_del(&blk->list);
return 0;
--
2.47.3
More information about the barebox
mailing list