diff options
Diffstat (limited to 'block/blk-lib.c')
-rw-r--r-- | block/blk-lib.c | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/block/blk-lib.c b/block/blk-lib.c index 76f867ea9a9b..5f2c429d4378 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c | |||
@@ -51,16 +51,14 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, | |||
51 | if ((sector | nr_sects) & bs_mask) | 51 | if ((sector | nr_sects) & bs_mask) |
52 | return -EINVAL; | 52 | return -EINVAL; |
53 | 53 | ||
54 | while (nr_sects) { | 54 | if (!nr_sects) |
55 | unsigned int req_sects = nr_sects; | 55 | return -EINVAL; |
56 | sector_t end_sect; | ||
57 | 56 | ||
58 | if (!req_sects) | 57 | while (nr_sects) { |
59 | goto fail; | 58 | sector_t req_sects = min_t(sector_t, nr_sects, |
60 | if (req_sects > UINT_MAX >> 9) | 59 | bio_allowed_max_sectors(q)); |
61 | req_sects = UINT_MAX >> 9; | ||
62 | 60 | ||
63 | end_sect = sector + req_sects; | 61 | WARN_ON_ONCE((req_sects << 9) > UINT_MAX); |
64 | 62 | ||
65 | bio = blk_next_bio(bio, 0, gfp_mask); | 63 | bio = blk_next_bio(bio, 0, gfp_mask); |
66 | bio->bi_iter.bi_sector = sector; | 64 | bio->bi_iter.bi_sector = sector; |
@@ -68,8 +66,8 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, | |||
68 | bio_set_op_attrs(bio, op, 0); | 66 | bio_set_op_attrs(bio, op, 0); |
69 | 67 | ||
70 | bio->bi_iter.bi_size = req_sects << 9; | 68 | bio->bi_iter.bi_size = req_sects << 9; |
69 | sector += req_sects; | ||
71 | nr_sects -= req_sects; | 70 | nr_sects -= req_sects; |
72 | sector = end_sect; | ||
73 | 71 | ||
74 | /* | 72 | /* |
75 | * We can loop for a long time in here, if someone does | 73 | * We can loop for a long time in here, if someone does |
@@ -82,14 +80,6 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, | |||
82 | 80 | ||
83 | *biop = bio; | 81 | *biop = bio; |
84 | return 0; | 82 | return 0; |
85 | |||
86 | fail: | ||
87 | if (bio) { | ||
88 | submit_bio_wait(bio); | ||
89 | bio_put(bio); | ||
90 | } | ||
91 | *biop = NULL; | ||
92 | return -EOPNOTSUPP; | ||
93 | } | 83 | } |
94 | EXPORT_SYMBOL(__blkdev_issue_discard); | 84 | EXPORT_SYMBOL(__blkdev_issue_discard); |
95 | 85 | ||
@@ -161,7 +151,7 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector, | |||
161 | return -EOPNOTSUPP; | 151 | return -EOPNOTSUPP; |
162 | 152 | ||
163 | /* Ensure that max_write_same_sectors doesn't overflow bi_size */ | 153 | /* Ensure that max_write_same_sectors doesn't overflow bi_size */ |
164 | max_write_same_sectors = UINT_MAX >> 9; | 154 | max_write_same_sectors = bio_allowed_max_sectors(q); |
165 | 155 | ||
166 | while (nr_sects) { | 156 | while (nr_sects) { |
167 | bio = blk_next_bio(bio, 1, gfp_mask); | 157 | bio = blk_next_bio(bio, 1, gfp_mask); |