diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2008-09-03 09:17:14 -0400 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2008-09-05 13:01:59 -0400 |
commit | f171d4d769c8ccac6675892960e37f6485837fae (patch) | |
tree | 60236e7749d9e9e8bd7a383214fba6aaaa6dcb2d /fs | |
parent | 7c7cbadf7341a0792879c67d6e3020f040d6cd7f (diff) |
UBIFS: fix division by zero
If fanout is 3, we have division by zero in
'ubifs_read_superblock()':
divide error: 0000 [#1] PREEMPT SMP
Pid: 28744, comm: mount Not tainted (2.6.27-rc4-ubifs-2.6 #23)
EIP: 0060:[<f8f9e3ef>] EFLAGS: 00010202 CPU: 0
EIP is at ubifs_reported_space+0x2d/0x69 [ubifs]
EAX: 00000000 EBX: 00000000 ECX: 00000000 EDX: 00000000
ESI: 00000000 EDI: f0ae64b0 EBP: f1f9fcf4 ESP: f1f9fce0
DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ubifs/budget.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/fs/ubifs/budget.c b/fs/ubifs/budget.c index 101d278c591d..73db464cd08b 100644 --- a/fs/ubifs/budget.c +++ b/fs/ubifs/budget.c | |||
@@ -723,24 +723,25 @@ void ubifs_release_dirty_inode_budget(struct ubifs_info *c, | |||
723 | */ | 723 | */ |
724 | long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free) | 724 | long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free) |
725 | { | 725 | { |
726 | int divisor, factor; | 726 | int divisor, factor, f; |
727 | 727 | ||
728 | /* | 728 | /* |
729 | * Reported space size is @free * X, where X is UBIFS block size | 729 | * Reported space size is @free * X, where X is UBIFS block size |
730 | * divided by UBIFS block size + all overhead one data block | 730 | * divided by UBIFS block size + all overhead one data block |
731 | * introduces. The overhead is the node header + indexing overhead. | 731 | * introduces. The overhead is the node header + indexing overhead. |
732 | * | 732 | * |
733 | * Indexing overhead is calculations are based on the following | 733 | * Indexing overhead calculations are based on the following formula: |
734 | * formula: I = N/(f - 1) + 1, where I - number of indexing nodes, N - | 734 | * I = N/(f - 1) + 1, where I - number of indexing nodes, N - number |
735 | * number of data nodes, f - fanout. Because effective UBIFS fanout is | 735 | * of data nodes, f - fanout. Because effective UBIFS fanout is twice |
736 | * twice as less than maximum fanout, we assume that each data node | 736 | * as less than maximum fanout, we assume that each data node |
737 | * introduces 3 * @c->max_idx_node_sz / (@c->fanout/2 - 1) bytes. | 737 | * introduces 3 * @c->max_idx_node_sz / (@c->fanout/2 - 1) bytes. |
738 | * Note, the multiplier 3 is because UBIFS reseves thrice as more space | 738 | * Note, the multiplier 3 is because UBIFS reseves thrice as more space |
739 | * for the index. | 739 | * for the index. |
740 | */ | 740 | */ |
741 | f = c->fanout > 3 ? c->fanout >> 1 : 2; | ||
741 | factor = UBIFS_BLOCK_SIZE; | 742 | factor = UBIFS_BLOCK_SIZE; |
742 | divisor = UBIFS_MAX_DATA_NODE_SZ; | 743 | divisor = UBIFS_MAX_DATA_NODE_SZ; |
743 | divisor += (c->max_idx_node_sz * 3) / ((c->fanout >> 1) - 1); | 744 | divisor += (c->max_idx_node_sz * 3) / (f - 1); |
744 | free *= factor; | 745 | free *= factor; |
745 | do_div(free, divisor); | 746 | do_div(free, divisor); |
746 | return free; | 747 | return free; |