diff options
-rw-r--r-- | block/blk-lib.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/block/blk-lib.c b/block/blk-lib.c index d6f50d572565..9b5b561cb928 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c | |||
@@ -43,8 +43,8 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, | |||
43 | DECLARE_COMPLETION_ONSTACK(wait); | 43 | DECLARE_COMPLETION_ONSTACK(wait); |
44 | struct request_queue *q = bdev_get_queue(bdev); | 44 | struct request_queue *q = bdev_get_queue(bdev); |
45 | int type = REQ_WRITE | REQ_DISCARD; | 45 | int type = REQ_WRITE | REQ_DISCARD; |
46 | sector_t max_discard_sectors; | 46 | unsigned int max_discard_sectors, granularity; |
47 | sector_t granularity, alignment; | 47 | int alignment; |
48 | struct bio_batch bb; | 48 | struct bio_batch bb; |
49 | struct bio *bio; | 49 | struct bio *bio; |
50 | int ret = 0; | 50 | int ret = 0; |
@@ -58,16 +58,14 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, | |||
58 | 58 | ||
59 | /* Zero-sector (unknown) and one-sector granularities are the same. */ | 59 | /* Zero-sector (unknown) and one-sector granularities are the same. */ |
60 | granularity = max(q->limits.discard_granularity >> 9, 1U); | 60 | granularity = max(q->limits.discard_granularity >> 9, 1U); |
61 | alignment = bdev_discard_alignment(bdev) >> 9; | 61 | alignment = (bdev_discard_alignment(bdev) >> 9) % granularity; |
62 | alignment = sector_div(alignment, granularity); | ||
63 | 62 | ||
64 | /* | 63 | /* |
65 | * Ensure that max_discard_sectors is of the proper | 64 | * Ensure that max_discard_sectors is of the proper |
66 | * granularity, so that requests stay aligned after a split. | 65 | * granularity, so that requests stay aligned after a split. |
67 | */ | 66 | */ |
68 | max_discard_sectors = min(q->limits.max_discard_sectors, UINT_MAX >> 9); | 67 | max_discard_sectors = min(q->limits.max_discard_sectors, UINT_MAX >> 9); |
69 | sector_div(max_discard_sectors, granularity); | 68 | max_discard_sectors -= max_discard_sectors % granularity; |
70 | max_discard_sectors *= granularity; | ||
71 | if (unlikely(!max_discard_sectors)) { | 69 | if (unlikely(!max_discard_sectors)) { |
72 | /* Avoid infinite loop below. Being cautious never hurts. */ | 70 | /* Avoid infinite loop below. Being cautious never hurts. */ |
73 | return -EOPNOTSUPP; | 71 | return -EOPNOTSUPP; |