block: fix incorrect branching in blk_max_size_offset()
authorMike Snitzer <snitzer@redhat.com>
Fri, 4 Dec 2020 22:21:03 +0000 (17:21 -0500)
committerMike Snitzer <snitzer@redhat.com>
Fri, 4 Dec 2020 22:27:42 +0000 (17:27 -0500)
If non-zero 'chunk_sectors' is passed in to blk_max_size_offset() that
override will be incorrectly ignored.

Old blk_max_size_offset() branching, prior to commit 3ee16db390b4,
must be used only if passed 'chunk_sectors' override is zero.

Fixes: 3ee16db390b4 ("dm: fix IO splitting")
Cc: stable@vger.kernel.org # 5.9
Reported-by: John Dorminy <jdorminy@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
include/linux/blkdev.h

index 24ae504..033eb5f 100644 (file)
@@ -1076,10 +1076,12 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q,
                                               sector_t offset,
                                               unsigned int chunk_sectors)
 {
-       if (!chunk_sectors && q->limits.chunk_sectors)
-               chunk_sectors = q->limits.chunk_sectors;
-       else
-               return q->limits.max_sectors;
+       if (!chunk_sectors) {
+               if (q->limits.chunk_sectors)
+                       chunk_sectors = q->limits.chunk_sectors;
+               else
+                       return q->limits.max_sectors;
+       }
 
        if (likely(is_power_of_2(chunk_sectors)))
                chunk_sectors -= offset & (chunk_sectors - 1);