Skip to content

Commit

Permalink
block: cleanup __blkdev_issue_discard()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ming Lei authored and Jens Axboe committed Nov 9, 2018
1 parent 1adfc5e commit ba5d738
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions block/blk-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,21 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
if ((sector | nr_sects) & bs_mask)
return -EINVAL;

while (nr_sects) {
unsigned int req_sects = nr_sects;
sector_t end_sect;

if (!req_sects)
goto fail;
req_sects = min(req_sects, bio_allowed_max_sectors(q));
if (!nr_sects)
return -EINVAL;

end_sect = sector + req_sects;
while (nr_sects) {
unsigned int req_sects = min_t(unsigned int, nr_sects,
bio_allowed_max_sectors(q));

bio = blk_next_bio(bio, 0, gfp_mask);
bio->bi_iter.bi_sector = sector;
bio_set_dev(bio, bdev);
bio_set_op_attrs(bio, op, 0);

bio->bi_iter.bi_size = req_sects << 9;
sector += req_sects;
nr_sects -= req_sects;
sector = end_sect;

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

*biop = bio;
return 0;

fail:
if (bio) {
submit_bio_wait(bio);
bio_put(bio);
}
*biop = NULL;
return -EOPNOTSUPP;
}
EXPORT_SYMBOL(__blkdev_issue_discard);

Expand Down

0 comments on commit ba5d738

Please sign in to comment.