Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a5b5c958 authored by WANG Cong's avatar WANG Cong Committed by David S. Miller
Browse files

net_sched: act: refactor cleanup ops



For bindcnt and refcnt etc., they are common for all actions,
not need to repeat such operations for their own, they can be unified
now. Actions just need to do its specific cleanup if needed.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarJamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 86062033
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ struct tc_action_ops {
	struct module		*owner;
	int     (*act)(struct sk_buff *, const struct tc_action *, struct tcf_result *);
	int     (*dump)(struct sk_buff *, struct tc_action *, int, int);
	int     (*cleanup)(struct tc_action *, int bind);
	void	(*cleanup)(struct tc_action *, int bind);
	int     (*lookup)(struct tc_action *, u32);
	int     (*init)(struct net *net, struct nlattr *nla,
			struct nlattr *est, struct tc_action *act, int ovr,
+5 −3
Original line number Diff line number Diff line
@@ -56,6 +56,8 @@ int tcf_hash_release(struct tc_action *a, int bind)

		p->tcfc_refcnt--;
		if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) {
			if (a->ops->cleanup)
				a->ops->cleanup(a, bind);
			tcf_hash_destroy(a);
			ret = 1;
		}
@@ -277,8 +279,8 @@ int tcf_register_action(struct tc_action_ops *act)
{
	struct tc_action_ops *a;

	/* Must supply act, dump, cleanup and init */
	if (!act->act || !act->dump || !act->cleanup || !act->init)
	/* Must supply act, dump and init */
	if (!act->act || !act->dump || !act->init)
		return -EINVAL;

	/* Supply defaults */
@@ -390,7 +392,7 @@ void tcf_action_destroy(struct list_head *actions, int bind)
	struct tc_action *a, *tmp;

	list_for_each_entry_safe(a, tmp, actions, list) {
		if (a->ops->cleanup(a, bind) == ACT_P_DELETED)
		if (tcf_hash_release(a, bind) == ACT_P_DELETED)
			module_put(a->ops->owner);
		list_del(&a->list);
		kfree(a);
+0 −1
Original line number Diff line number Diff line
@@ -566,7 +566,6 @@ static struct tc_action_ops act_csum_ops = {
	.owner		= THIS_MODULE,
	.act		= tcf_csum,
	.dump		= tcf_csum_dump,
	.cleanup	= tcf_hash_release,
	.init		= tcf_csum_init,
};

+0 −1
Original line number Diff line number Diff line
@@ -185,7 +185,6 @@ static struct tc_action_ops act_gact_ops = {
	.owner		=	THIS_MODULE,
	.act		=	tcf_gact,
	.dump		=	tcf_gact_dump,
	.cleanup	=	tcf_hash_release,
	.init		=	tcf_gact_init,
};

+5 −16
Original line number Diff line number Diff line
@@ -69,23 +69,12 @@ static void ipt_destroy_target(struct xt_entry_target *t)
	module_put(par.target->me);
}

static int tcf_ipt_release(struct tc_action *a, int bind)
static void tcf_ipt_release(struct tc_action *a, int bind)
{
	struct tcf_ipt *ipt = to_ipt(a);
	int ret = 0;
	if (ipt) {
		if (bind)
			ipt->tcf_bindcnt--;
		ipt->tcf_refcnt--;
		if (ipt->tcf_bindcnt <= 0 && ipt->tcf_refcnt <= 0) {
	ipt_destroy_target(ipt->tcfi_t);
	kfree(ipt->tcfi_tname);
	kfree(ipt->tcfi_t);
			tcf_hash_destroy(a);
			ret = ACT_P_DELETED;
		}
	}
	return ret;
}

static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] = {
@@ -133,7 +122,7 @@ static int tcf_ipt_init(struct net *net, struct nlattr *nla, struct nlattr *est,
	} else {
		if (bind)/* dont override defaults */
			return 0;
		tcf_ipt_release(a, bind);
		tcf_hash_release(a, bind);

		if (!ovr)
			return -EEXIST;
Loading