Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiri Kosina <jkosina@suse.cz>2013-04-02 15:01:38 +0200
committerJiri Kosina <jkosina@suse.cz>2013-04-02 15:01:38 +0200
commitec2ce3a3879d86a8ccbe4eb21ff5c4c80aaf5ae3 (patch)
tree417d036514004f395b94c8f2a0135f796a9f839d
parent6d252e1873143a6629e41b8ffa6c08d1cc69b1eb (diff)
blk: avoid divide-by-zero with zero discard granularityrpm-3.0.70-0.9
-rw-r--r--include/linux/blkdev.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 88854d0a1f69..994200636300 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1118,14 +1118,25 @@ static inline int queue_discard_alignment(struct request_queue *q)
static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector)
{
- sector_t alignment = sector << 9;
- alignment = sector_div(alignment, lim->discard_granularity);
+ unsigned int alignment, granularity, offset;
if (!lim->max_discard_sectors)
return 0;
- alignment = lim->discard_granularity + lim->discard_alignment - alignment;
- return sector_div(alignment, lim->discard_granularity);
+ /* Why are these in bytes, not sectors? */
+ alignment = lim->discard_alignment >> 9;
+ granularity = lim->discard_granularity >> 9;
+ if (!granularity)
+ return 0;
+
+ /* Offset of the partition start in 'granularity' sectors */
+ offset = sector_div(sector, granularity);
+
+ /* And why do we do this modulus *again* in blkdev_issue_discard()? */
+ offset = (granularity + alignment - offset) % granularity;
+
+ /* Turn it back into bytes, gaah */
+ return offset << 9;
}
static inline int bdev_discard_alignment(struct block_device *bdev)