aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/regmap/regcache-rbtree.c
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-04-04 17:48:33 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-04-04 18:22:15 -0400
commitc04c1b9ee8f30c7a3a25e20e406247003f634ebe (patch)
treec8f1de34051bce402ee5be5d6dfadc4bc7e47ae1 /drivers/base/regmap/regcache-rbtree.c
parente466de05194b666114713b753e2f4be1d4200140 (diff)
regmap: prevent division by zero in rbtree_show
If there are no nodes in the cache, nodes will be 0, so calculating "registers / nodes" will cause division by zero. Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Cc: stable@vger.kernel.org
Diffstat (limited to 'drivers/base/regmap/regcache-rbtree.c')
-rw-r--r--drivers/base/regmap/regcache-rbtree.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c
index 5157fa04c2f0..ea76a90630bf 100644
--- a/drivers/base/regmap/regcache-rbtree.c
+++ b/drivers/base/regmap/regcache-rbtree.c
@@ -138,6 +138,7 @@ static int rbtree_show(struct seq_file *s, void *ignored)
138 unsigned int base, top; 138 unsigned int base, top;
139 int nodes = 0; 139 int nodes = 0;
140 int registers = 0; 140 int registers = 0;
141 int average;
141 142
142 mutex_lock(&map->lock); 143 mutex_lock(&map->lock);
143 144
@@ -152,8 +153,13 @@ static int rbtree_show(struct seq_file *s, void *ignored)
152 registers += top - base + 1; 153 registers += top - base + 1;
153 } 154 }
154 155
156 if (nodes)
157 average = registers / nodes;
158 else
159 average = 0;
160
155 seq_printf(s, "%d nodes, %d registers, average %d registers\n", 161 seq_printf(s, "%d nodes, %d registers, average %d registers\n",
156 nodes, registers, registers / nodes); 162 nodes, registers, average);
157 163
158 mutex_unlock(&map->lock); 164 mutex_unlock(&map->lock);
159 165