diff options
Diffstat (limited to 'block/blk-lib.c')
-rw-r--r-- | block/blk-lib.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/block/blk-lib.c b/block/blk-lib.c index 78e627e2581d..2b461b496a78 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c | |||
@@ -59,7 +59,10 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, | |||
59 | * granularity | 59 | * granularity |
60 | */ | 60 | */ |
61 | max_discard_sectors = min(q->limits.max_discard_sectors, UINT_MAX >> 9); | 61 | max_discard_sectors = min(q->limits.max_discard_sectors, UINT_MAX >> 9); |
62 | if (q->limits.discard_granularity) { | 62 | if (unlikely(!max_discard_sectors)) { |
63 | /* Avoid infinite loop below. Being cautious never hurts. */ | ||
64 | return -EOPNOTSUPP; | ||
65 | } else if (q->limits.discard_granularity) { | ||
63 | unsigned int disc_sects = q->limits.discard_granularity >> 9; | 66 | unsigned int disc_sects = q->limits.discard_granularity >> 9; |
64 | 67 | ||
65 | max_discard_sectors &= ~(disc_sects - 1); | 68 | max_discard_sectors &= ~(disc_sects - 1); |