summaryrefslogtreecommitdiff
path: root/drivers/md
diff options
context:
space:
mode:
authorMike Snitzer <snitzer@kernel.org>2023-03-25 04:36:26 +0300
committerMike Snitzer <snitzer@kernel.org>2023-03-30 22:57:50 +0300
commit0511228752eaa5264ada8b1f4baeded916c65945 (patch)
tree42c99c0a352cd4615d9a5a3f54a6f2366fb23e87 /drivers/md
parent555977dd6818da3bcf39ca5a3c1cb7e8ca4298c1 (diff)
downloadlinux-0511228752eaa5264ada8b1f4baeded916c65945.tar.xz
dm bufio: never crash if dm_bufio_in_request()
All these instances are entirely avoidable given that they speak to coding mistakes that result in inappropriate use. Proper testing during development will catch any such coding bug so its best to relax all of these from BUG_ON to WARN_ON_ONCE. Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Diffstat (limited to 'drivers/md')
-rw-r--r--drivers/md/dm-bufio.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index dac9f1f84c34..d63f94ab1d9f 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -1152,7 +1152,8 @@ EXPORT_SYMBOL_GPL(dm_bufio_get);
void *dm_bufio_read(struct dm_bufio_client *c, sector_t block,
struct dm_buffer **bp)
{
- BUG_ON(dm_bufio_in_request());
+ if (WARN_ON_ONCE(dm_bufio_in_request()))
+ return ERR_PTR(-EINVAL);
return new_read(c, block, NF_READ, bp);
}
@@ -1161,7 +1162,8 @@ EXPORT_SYMBOL_GPL(dm_bufio_read);
void *dm_bufio_new(struct dm_bufio_client *c, sector_t block,
struct dm_buffer **bp)
{
- BUG_ON(dm_bufio_in_request());
+ if (WARN_ON_ONCE(dm_bufio_in_request()))
+ return ERR_PTR(-EINVAL);
return new_read(c, block, NF_FRESH, bp);
}
@@ -1174,7 +1176,8 @@ void dm_bufio_prefetch(struct dm_bufio_client *c,
LIST_HEAD(write_list);
- BUG_ON(dm_bufio_in_request());
+ if (WARN_ON_ONCE(dm_bufio_in_request()))
+ return; /* should never happen */
blk_start_plug(&plug);
dm_bufio_lock(c);
@@ -1281,7 +1284,8 @@ void dm_bufio_write_dirty_buffers_async(struct dm_bufio_client *c)
{
LIST_HEAD(write_list);
- BUG_ON(dm_bufio_in_request());
+ if (WARN_ON_ONCE(dm_bufio_in_request()))
+ return; /* should never happen */
dm_bufio_lock(c);
__write_dirty_buffers_async(c, 0, &write_list);
@@ -1386,7 +1390,8 @@ int dm_bufio_issue_flush(struct dm_bufio_client *c)
.count = 0,
};
- BUG_ON(dm_bufio_in_request());
+ if (WARN_ON_ONCE(dm_bufio_in_request()))
+ return -EINVAL;
return dm_io(&io_req, 1, &io_reg, NULL);
}
@@ -1409,7 +1414,8 @@ int dm_bufio_issue_discard(struct dm_bufio_client *c, sector_t block, sector_t c
.count = block_to_sector(c, count),
};
- BUG_ON(dm_bufio_in_request());
+ if (WARN_ON_ONCE(dm_bufio_in_request()))
+ return -EINVAL; /* discards are optional */
return dm_io(&io_req, 1, &io_reg, NULL);
}