static void basic_delete_filter(struct rcu_head *head)
 {
        struct basic_filter *f = container_of(head, struct basic_filter, rcu);
-       struct tcf_proto *tp = f->tp;
 
-       tcf_unbind_filter(tp, &f->res);
        tcf_exts_destroy(&f->exts);
        tcf_em_tree_destroy(&f->ematches);
        kfree(f);
 
        list_for_each_entry_safe(f, n, &head->flist, link) {
                list_del_rcu(&f->link);
+               tcf_unbind_filter(tp, &f->res);
                call_rcu(&f->rcu, basic_delete_filter);
        }
        RCU_INIT_POINTER(tp->root, NULL);
        list_for_each_entry(t, &head->flist, link)
                if (t == f) {
                        list_del_rcu(&t->link);
+                       tcf_unbind_filter(tp, &t->res);
                        call_rcu(&t->rcu, basic_delete_filter);
                        return 0;
                }
 
        if (fold) {
                list_replace_rcu(&fold->link, &fnew->link);
+               tcf_unbind_filter(tp, &fold->res);
                call_rcu(&fold->rcu, basic_delete_filter);
        } else {
                list_add_rcu(&fnew->link, &head->flist);
 
 
 static void cls_bpf_delete_prog(struct tcf_proto *tp, struct cls_bpf_prog *prog)
 {
-       tcf_unbind_filter(tp, &prog->res);
        tcf_exts_destroy(&prog->exts);
 
        bpf_prog_destroy(prog->filter);
        list_for_each_entry(prog, &head->plist, link) {
                if (prog == todel) {
                        list_del_rcu(&prog->link);
+                       tcf_unbind_filter(tp, &prog->res);
                        call_rcu(&prog->rcu, __cls_bpf_delete_prog);
                        return 0;
                }
 
        list_for_each_entry_safe(prog, tmp, &head->plist, link) {
                list_del_rcu(&prog->link);
+               tcf_unbind_filter(tp, &prog->res);
                call_rcu(&prog->rcu, __cls_bpf_delete_prog);
        }
 
 
        if (oldprog) {
                list_replace_rcu(&prog->link, &oldprog->link);
+               tcf_unbind_filter(tp, &oldprog->res);
                call_rcu(&oldprog->rcu, __cls_bpf_delete_prog);
        } else {
                list_add_rcu(&prog->link, &head->plist);
 
 static void fw_delete_filter(struct rcu_head *head)
 {
        struct fw_filter *f = container_of(head, struct fw_filter, rcu);
-       struct tcf_proto *tp = f->tp;
 
-       tcf_unbind_filter(tp, &f->res);
        tcf_exts_destroy(&f->exts);
        kfree(f);
 }
                while ((f = rtnl_dereference(head->ht[h])) != NULL) {
                        RCU_INIT_POINTER(head->ht[h],
                                         rtnl_dereference(f->next));
+                       tcf_unbind_filter(tp, &f->res);
                        call_rcu(&f->rcu, fw_delete_filter);
                }
        }
             fp = &pfp->next, pfp = rtnl_dereference(*fp)) {
                if (pfp == f) {
                        RCU_INIT_POINTER(*fp, rtnl_dereference(f->next));
+                       tcf_unbind_filter(tp, &f->res);
                        call_rcu(&f->rcu, fw_delete_filter);
                        return 0;
                }
 
                RCU_INIT_POINTER(fnew->next, rtnl_dereference(pfp->next));
                rcu_assign_pointer(*fp, fnew);
+               tcf_unbind_filter(tp, &f->res);
                call_rcu(&f->rcu, fw_delete_filter);
 
                *arg = (unsigned long)fnew;
 
 route4_delete_filter(struct rcu_head *head)
 {
        struct route4_filter *f = container_of(head, struct route4_filter, rcu);
-       struct tcf_proto *tp = f->tp;
 
-       tcf_unbind_filter(tp, &f->res);
        tcf_exts_destroy(&f->exts);
        kfree(f);
 }
 
                                        next = rtnl_dereference(f->next);
                                        RCU_INIT_POINTER(b->ht[h2], next);
+                                       tcf_unbind_filter(tp, &f->res);
                                        call_rcu(&f->rcu, route4_delete_filter);
                                }
                        }
                        route4_reset_fastmap(head);
 
                        /* Delete it */
+                       tcf_unbind_filter(tp, &f->res);
                        call_rcu(&f->rcu, route4_delete_filter);
 
                        /* Strip RTNL protected tree */
 
        route4_reset_fastmap(head);
        *arg = (unsigned long)f;
-       if (fold)
+       if (fold) {
+               tcf_unbind_filter(tp, &fold->res);
                call_rcu(&fold->rcu, route4_delete_filter);
+       }
        return 0;
 
 errout: