Skip to content

Commit c04c1b9

Browse files
nvswarrenbroonie
authored andcommitted
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 <[email protected]> Signed-off-by: Mark Brown <[email protected]> Cc: [email protected]
1 parent e466de0 commit c04c1b9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/base/regmap/regcache-rbtree.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ static int rbtree_show(struct seq_file *s, void *ignored)
138138
unsigned int base, top;
139139
int nodes = 0;
140140
int registers = 0;
141+
int average;
141142

142143
mutex_lock(&map->lock);
143144

@@ -152,8 +153,13 @@ static int rbtree_show(struct seq_file *s, void *ignored)
152153
registers += top - base + 1;
153154
}
154155

156+
if (nodes)
157+
average = registers / nodes;
158+
else
159+
average = 0;
160+
155161
seq_printf(s, "%d nodes, %d registers, average %d registers\n",
156-
nodes, registers, registers / nodes);
162+
nodes, registers, average);
157163

158164
mutex_unlock(&map->lock);
159165

0 commit comments

Comments
 (0)