diff --git a/src/plugins/topology/tree/topology_tree.c b/src/plugins/topology/tree/topology_tree.c
index 0033bd3a1283f939f4abb93ea6226f2b9f120005..1b422af0455700bf20d3dad94ae588e055f2c57a 100644
--- a/src/plugins/topology/tree/topology_tree.c
+++ b/src/plugins/topology/tree/topology_tree.c
@@ -375,6 +375,8 @@ static void _validate_switches(void)
 		}
 		if (resolved)
 			break;
+		if (depth > 20)	/* Prevent infinite loop */
+			fatal("Switch configuration is not a tree");
 	}
 
 	switch_levels = 0;