summaryrefslogtreecommitdiff
path: root/common/block.c
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-08-23 19:52:41 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-08-31 08:30:08 +0200
commitd83ad9d3123a1ae26aef033eaa70c06952ba1243 (patch)
treee7a83bea1a0b3d97f26cdb1691f048c50ca3494e /common/block.c
parenta4b7204f40888d87f4a2c48522bb0264a05fc960 (diff)
downloadbarebox-d83ad9d3123a1ae26aef033eaa70c06952ba1243.tar.gz
block: Do not ignore error in blk->ops->write()
Getting a error from blk->ops->write() is not a very unlikely event (happens quite often during new board bringup), so we need to catch and propagate them to upper layers so they can be at least reported properly. Change the code of all of the callers to bail out as soon as blk->ops->write() fails. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/block.c')
-rw-r--r--common/block.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/common/block.c b/common/block.c
index 219b943afc..8d0de42d90 100644
--- a/common/block.c
+++ b/common/block.c
@@ -44,13 +44,17 @@ struct chunk {
static int writebuffer_flush(struct block_device *blk)
{
struct chunk *chunk;
+ int ret;
if (!IS_ENABLED(CONFIG_BLOCK_WRITE))
return 0;
list_for_each_entry(chunk, &blk->buffered_blocks, list) {
if (chunk->dirty) {
- blk->ops->write(blk, chunk->data, chunk->block_start, blk->rdbufsize);
+ ret = blk->ops->write(blk, chunk->data, chunk->block_start, blk->rdbufsize);
+ if (ret < 0)
+ return ret;
+
chunk->dirty = 0;
}
}
@@ -107,6 +111,7 @@ static void *block_get_cached(struct block_device *blk, int block)
static struct chunk *get_chunk(struct block_device *blk)
{
struct chunk *chunk;
+ int ret;
if (list_empty(&blk->idle_blocks)) {
/* use last entry which is the most unused */
@@ -114,8 +119,11 @@ static struct chunk *get_chunk(struct block_device *blk)
if (chunk->dirty) {
size_t num_blocks = min(blk->rdbufsize,
blk->num_blocks - chunk->block_start);
- blk->ops->write(blk, chunk->data, chunk->block_start,
- num_blocks);
+ ret = blk->ops->write(blk, chunk->data, chunk->block_start,
+ num_blocks);
+ if (ret < 0)
+ return ERR_PTR(ret);
+
chunk->dirty = 0;
}
@@ -140,6 +148,9 @@ static int block_cache(struct block_device *blk, int block)
int ret;
chunk = get_chunk(blk);
+ if (IS_ERR(chunk))
+ return PTR_ERR(chunk);
+
chunk->block_start = block & ~blk->blkmask;
debug("%s: %d to %d\n", __func__, chunk->block_start,