diff --git a/libspi/collection.c b/libspi/collection.c
index 7fbacb7..a33650a 100644
--- a/libspi/collection.c
+++ b/libspi/collection.c
@@ -610,7 +610,8 @@ sort_order_rev_canonical (MatchRulePrivate *mrp, GList *ls,
     if (flag && match_interfaces_lookup (obj, mrp, ev) 
                && match_states_lookup (obj, mrp, ev)     
                && match_roles_lookup (obj, mrp, ev)  
-               && match_attributes_lookup (obj, mrp, ev))
+               && match_attributes_lookup (obj, mrp, ev)
+               && kount < max)
     {
          ls = g_list_append (ls, obj);
          kount++;
