From: Keith Busch <kbusch@xxxxxxxxxx> We're already iterating every segment, so check alignment for a valid IO at the same time. We had depended on these constraints were already checked prior to splitting, but let's put more responsibility here since splitting iterates each segment before dispatching to the driver anyway. This way, upper layers don't need to concern themselves with it. Signed-off-by: Keith Busch <kbusch@xxxxxxxxxx> --- block/blk-merge.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/blk-merge.c b/block/blk-merge.c index 70d704615be52..81bdad915699a 100644 --- a/block/blk-merge.c +++ b/block/blk-merge.c @@ -298,6 +298,9 @@ int bio_split_rw_at(struct bio *bio, const struct queue_limits *lim, unsigned nsegs = 0, bytes = 0; bio_for_each_bvec(bv, bio, iter) { + if (bv.bv_offset & lim->dma_alignment) + return -EINVAL; + /* * If the queue doesn't support SG gaps and adding this * offset would create a gap, disallow it. @@ -341,6 +344,8 @@ int bio_split_rw_at(struct bio *bio, const struct queue_limits *lim, * we do not use the full hardware limits. */ bytes = ALIGN_DOWN(bytes, bio_split_alignment(bio, lim)); + if (!bytes) + return -EINVAL; /* * Bio splitting may cause subtle trouble such as hang when doing sync -- 2.47.3