]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
regmap: prevent division by zero in rbtree_show
authorStephen Warren <swarren@nvidia.com>
Wed, 4 Apr 2012 21:48:33 +0000 (15:48 -0600)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 13 Apr 2012 16:13:55 +0000 (09:13 -0700)
commit c04c1b9ee8f30c7a3a25e20e406247003f634ebe upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/regmap/regcache-rbtree.c

index 32620c4f16834112ab88c9f9741750aee94f26d6..d1179fdff081406226946ce26387b15236ea07a7 100644 (file)
@@ -137,6 +137,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);
 
@@ -151,8 +152,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);