[ 60/78] regmap: prevent division by zero in rbtree_show

From: Greg KH
Date: Wed Apr 11 2012 - 19:54:23 EST


3.3-stable review patch. If anyone has any objections, please let me know.

------------------

From: Stephen Warren <swarren@xxxxxxxxxx>

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@xxxxxxxxxx>
Signed-off-by: Mark Brown <broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
drivers/base/regmap/regcache-rbtree.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

--- a/drivers/base/regmap/regcache-rbtree.c
+++ b/drivers/base/regmap/regcache-rbtree.c
@@ -137,6 +137,7 @@ static int rbtree_show(struct seq_file *
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 *
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);



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/