Skip to content

Commit ba5d738

Browse files
Ming Leiaxboe
authored andcommitted
block: cleanup __blkdev_issue_discard()
Cleanup __blkdev_issue_discard() a bit: - remove local variable of 'end_sect' - remove code block of 'fail' Cc: Mike Snitzer <snitzer@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Xiao Ni <xni@redhat.com> Cc: Mariusz Dabrowski <mariusz.dabrowski@intel.com> Tested-by: Rui Salvaterra <rsalvaterra@gmail.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 1adfc5e commit ba5d738

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

block/blk-lib.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,21 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
5151
if ((sector | nr_sects) & bs_mask)
5252
return -EINVAL;
5353

54-
while (nr_sects) {
55-
unsigned int req_sects = nr_sects;
56-
sector_t end_sect;
57-
58-
if (!req_sects)
59-
goto fail;
60-
req_sects = min(req_sects, bio_allowed_max_sectors(q));
54+
if (!nr_sects)
55+
return -EINVAL;
6156

62-
end_sect = sector + req_sects;
57+
while (nr_sects) {
58+
unsigned int req_sects = min_t(unsigned int, nr_sects,
59+
bio_allowed_max_sectors(q));
6360

6461
bio = blk_next_bio(bio, 0, gfp_mask);
6562
bio->bi_iter.bi_sector = sector;
6663
bio_set_dev(bio, bdev);
6764
bio_set_op_attrs(bio, op, 0);
6865

6966
bio->bi_iter.bi_size = req_sects << 9;
67+
sector += req_sects;
7068
nr_sects -= req_sects;
71-
sector = end_sect;
7269

7370
/*
7471
* We can loop for a long time in here, if someone does
@@ -81,14 +78,6 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
8178

8279
*biop = bio;
8380
return 0;
84-
85-
fail:
86-
if (bio) {
87-
submit_bio_wait(bio);
88-
bio_put(bio);
89-
}
90-
*biop = NULL;
91-
return -EOPNOTSUPP;
9281
}
9382
EXPORT_SYMBOL(__blkdev_issue_discard);
9483

0 commit comments

Comments
 (0)