[qca-nss-ecm] Fix assert on assignment remove

When a connection is destroyed classifier list assignments should be
removed whether the connection was inserted into the db or not.
This is because assignments are made before adding the connection into
the db but if the connection is not added, simply destroyed, the list will be corrupt.

Change-Id: I5b52b3e41ec684aff7ab2bf86863f6cb107c7e21
Signed-off-by: Gareth Williams <garethw@codeaurora.org>
diff --git a/ecm_db.c b/ecm_db.c
index db4fb06..abd3370 100644
--- a/ecm_db.c
+++ b/ecm_db.c
@@ -2284,6 +2284,7 @@
  */
 int ecm_db_connection_deref(struct ecm_db_connection_instance *ci)
 {
+	ecm_classifier_type_t ca_type;
 	int32_t i;
 
 	DEBUG_CHECK_MAGIC(ci, ECM_DB_CONNECTION_INSTANCE_MAGIC, "%p: magic failed", ci);
@@ -2300,6 +2301,26 @@
 	}
 
 	/*
+	 * Unlink from the "assignments by classifier type" lists.
+	 * 
+	 * This is done whether the connection is inserted into the database or not - this is because
+	 * classifier assignments take place before adding into the db.
+	 *
+	 * NOTE: We know that the ci is not being iterated in any of these lists because otherwise
+	 * ci would be being held as part of iteration and so we would not be here!
+	 * Equally we know that if the assignments_by_type[] element is non-null then it must also be in the relevant list too.
+	 */
+	for (ca_type = 0; ca_type < ECM_CLASSIFIER_TYPES; ++ca_type) {
+		if (!ci->assignments_by_type[ca_type]) {
+			/*
+			 * No assignment of this type, so would not be in the classifier type assignments list
+			 */
+			continue;
+		}
+		_ecm_db_classifier_type_assignment_remove(ci, ca_type);
+	}
+
+	/*
 	 * Remove from database if inserted
 	 */
 	if (!ci->flags & ECM_DB_CONNECTION_FLAGS_INSERTED) {
@@ -2310,7 +2331,6 @@
 		struct ecm_db_iface_instance *iface_to;
 		struct ecm_db_iface_instance *iface_nat_from;
 		struct ecm_db_iface_instance *iface_nat_to;
-		ecm_classifier_type_t ca_type;
 
 		/*
 		 * Remove it from the connection hash table
@@ -2558,21 +2578,6 @@
 		ecm_db_connection_count_by_protocol[ci->protocol]--;
 		DEBUG_ASSERT(ecm_db_connection_count_by_protocol[ci->protocol] >= 0, "%p: Invalid protocol count %d\n", ci, ecm_db_connection_count_by_protocol[ci->protocol]);
 
-		/*
-		 * Unlink from the "assignments by classifier type" lists
-		 * NOTE: We know that the ci is not being iterated in any of these lists because otherwise
-		 * ci would be being held as part of iteration and so we would not be here!
-		 * Equally we know that if the assignments_by_type[] element is non-null then it must also be in the relevant list too.
-		 */
-		for (ca_type = 0; ca_type < ECM_CLASSIFIER_TYPES; ++ca_type) {
-			if (!ci->assignments_by_type[ca_type]) {
-				/*
-				 * No assignment of this type, so would not be in the classifier type assignments list
-				 */
-				continue;
-			}
-			_ecm_db_classifier_type_assignment_remove(ci, ca_type);
-		}
 		spin_unlock_bh(&ecm_db_lock);
 
 		/*