/* This functions destroys an ematch tree previously created by tcf_em_tree_validate()/tcf_em_tree_change(). You must ensure that the ematch tree is not in use before calling this function.  */
void tcf_em_tree_destroy(struct tcf_proto *tp, struct tcf_ematch_tree *tree)
/* This functions destroys an ematch tree previously created by tcf_em_tree_validate()/tcf_em_tree_change(). You must ensure that the ematch tree is not in use before calling this function.  */
void tcf_em_tree_destroy(struct tcf_proto *tp, struct tcf_ematch_tree *tree)
{
	int i;
	if (tree->matches == NULL)
		return;
	for (i = 0; i < tree->hdr.nmatches; i++) {
		struct tcf_ematch *em = tcf_em_get_match(tree, i);
		if (em->ops) {
			if (em->ops->destroy)
				em->ops->destroy(tp, em);
			else if (!tcf_em_is_simple(em))
				kfree((void *) em->data);
			module_put(em->ops->owner);
		}
	}
	tree->hdr.nmatches = 0;
	kfree(tree->matches);
	tree->matches = NULL;
}