Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c04c1b9e authored by Stephen Warren's avatar Stephen Warren Committed by Mark Brown
Browse files

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: default avatarStephen Warren <swarren@nvidia.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Cc: stable@vger.kernel.org
parent e466de05
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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);