diff options
-rw-r--r-- | block/blk-settings.c | 6 | ||||
-rw-r--r-- | include/linux/lcm.h | 1 | ||||
-rw-r--r-- | lib/lcm.c | 11 |
3 files changed, 15 insertions, 3 deletions
diff --git a/block/blk-settings.c b/block/blk-settings.c index 6ed2cbe5e8c9..12600bfffca9 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c | |||
@@ -585,7 +585,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | |||
585 | b->physical_block_size); | 585 | b->physical_block_size); |
586 | 586 | ||
587 | t->io_min = max(t->io_min, b->io_min); | 587 | t->io_min = max(t->io_min, b->io_min); |
588 | t->io_opt = lcm(t->io_opt, b->io_opt); | 588 | t->io_opt = lcm_not_zero(t->io_opt, b->io_opt); |
589 | 589 | ||
590 | t->cluster &= b->cluster; | 590 | t->cluster &= b->cluster; |
591 | t->discard_zeroes_data &= b->discard_zeroes_data; | 591 | t->discard_zeroes_data &= b->discard_zeroes_data; |
@@ -616,7 +616,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | |||
616 | b->raid_partial_stripes_expensive); | 616 | b->raid_partial_stripes_expensive); |
617 | 617 | ||
618 | /* Find lowest common alignment_offset */ | 618 | /* Find lowest common alignment_offset */ |
619 | t->alignment_offset = lcm(t->alignment_offset, alignment) | 619 | t->alignment_offset = lcm_not_zero(t->alignment_offset, alignment) |
620 | % max(t->physical_block_size, t->io_min); | 620 | % max(t->physical_block_size, t->io_min); |
621 | 621 | ||
622 | /* Verify that new alignment_offset is on a logical block boundary */ | 622 | /* Verify that new alignment_offset is on a logical block boundary */ |
@@ -643,7 +643,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, | |||
643 | b->max_discard_sectors); | 643 | b->max_discard_sectors); |
644 | t->discard_granularity = max(t->discard_granularity, | 644 | t->discard_granularity = max(t->discard_granularity, |
645 | b->discard_granularity); | 645 | b->discard_granularity); |
646 | t->discard_alignment = lcm(t->discard_alignment, alignment) % | 646 | t->discard_alignment = lcm_not_zero(t->discard_alignment, alignment) % |
647 | t->discard_granularity; | 647 | t->discard_granularity; |
648 | } | 648 | } |
649 | 649 | ||
diff --git a/include/linux/lcm.h b/include/linux/lcm.h index 7bf01d779b45..1ce79a7f1daa 100644 --- a/include/linux/lcm.h +++ b/include/linux/lcm.h | |||
@@ -4,5 +4,6 @@ | |||
4 | #include <linux/compiler.h> | 4 | #include <linux/compiler.h> |
5 | 5 | ||
6 | unsigned long lcm(unsigned long a, unsigned long b) __attribute_const__; | 6 | unsigned long lcm(unsigned long a, unsigned long b) __attribute_const__; |
7 | unsigned long lcm_not_zero(unsigned long a, unsigned long b) __attribute_const__; | ||
7 | 8 | ||
8 | #endif /* _LCM_H */ | 9 | #endif /* _LCM_H */ |
@@ -12,3 +12,14 @@ unsigned long lcm(unsigned long a, unsigned long b) | |||
12 | return 0; | 12 | return 0; |
13 | } | 13 | } |
14 | EXPORT_SYMBOL_GPL(lcm); | 14 | EXPORT_SYMBOL_GPL(lcm); |
15 | |||
16 | unsigned long lcm_not_zero(unsigned long a, unsigned long b) | ||
17 | { | ||
18 | unsigned long l = lcm(a, b); | ||
19 | |||
20 | if (l) | ||
21 | return l; | ||
22 | |||
23 | return (b ? : a); | ||
24 | } | ||
25 | EXPORT_SYMBOL_GPL(lcm_not_zero); | ||