summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Warren <swarren@nvidia.com>2012-04-04 15:48:33 -0600
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-04-04 23:22:15 +0100
commitc04c1b9ee8f30c7a3a25e20e406247003f634ebe (patch)
treec8f1de34051bce402ee5be5d6dfadc4bc7e47ae1
parente466de05194b666114713b753e2f4be1d4200140 (diff)
downloadop-kernel-dev-c04c1b9ee8f30c7a3a25e20e406247003f634ebe.zip
op-kernel-dev-c04c1b9ee8f30c7a3a25e20e406247003f634ebe.tar.gz
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
-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 5157fa0..ea76a90 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)
unsigned int base, top;
int nodes = 0;
int registers = 0;
+ int average;
mutex_lock(&map->lock);
@@ -152,8 +153,13 @@ static int rbtree_show(struct seq_file *s, void *ignored)
registers += top - base + 1;
}
+ if (nodes)
+ average = registers / nodes;
+ else
+ average = 0;
+
seq_printf(s, "%d nodes, %d registers, average %d registers\n",
- nodes, registers, registers / nodes);
+ nodes, registers, average);
mutex_unlock(&map->lock);
OpenPOWER on IntegriCloud