tc: propogate errors from tcf_hash_create

Allow tcf_hash_create to return different errors on estimator failure.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Stephen Hemminger 2008-11-25 21:12:32 -08:00 committed by David S. Miller
parent 4ef8e76833
commit 0e991ec6a0
8 changed files with 27 additions and 19 deletions

View file

@ -214,12 +214,14 @@ struct tcf_common *tcf_hash_check(u32 index, struct tc_action *a, int bind,
} }
EXPORT_SYMBOL(tcf_hash_check); EXPORT_SYMBOL(tcf_hash_check);
struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a, int size, int bind, u32 *idx_gen, struct tcf_hashinfo *hinfo) struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est,
struct tc_action *a, int size, int bind,
u32 *idx_gen, struct tcf_hashinfo *hinfo)
{ {
struct tcf_common *p = kzalloc(size, GFP_KERNEL); struct tcf_common *p = kzalloc(size, GFP_KERNEL);
if (unlikely(!p)) if (unlikely(!p))
return p; return ERR_PTR(-ENOMEM);
p->tcfc_refcnt = 1; p->tcfc_refcnt = 1;
if (bind) if (bind)
p->tcfc_bindcnt = 1; p->tcfc_bindcnt = 1;
@ -228,9 +230,15 @@ struct tcf_common *tcf_hash_create(u32 index, struct nlattr *est, struct tc_acti
p->tcfc_index = index ? index : tcf_hash_new_index(idx_gen, hinfo); p->tcfc_index = index ? index : tcf_hash_new_index(idx_gen, hinfo);
p->tcfc_tm.install = jiffies; p->tcfc_tm.install = jiffies;
p->tcfc_tm.lastuse = jiffies; p->tcfc_tm.lastuse = jiffies;
if (est) if (est) {
gen_new_estimator(&p->tcfc_bstats, &p->tcfc_rate_est, int err = gen_new_estimator(&p->tcfc_bstats, &p->tcfc_rate_est,
&p->tcfc_lock, est); &p->tcfc_lock, est);
if (err) {
kfree(p);
return ERR_PTR(err);
}
}
a->priv = (void *) p; a->priv = (void *) p;
return p; return p;
} }

View file

@ -88,8 +88,8 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est,
if (!pc) { if (!pc) {
pc = tcf_hash_create(parm->index, est, a, sizeof(*gact), pc = tcf_hash_create(parm->index, est, a, sizeof(*gact),
bind, &gact_idx_gen, &gact_hash_info); bind, &gact_idx_gen, &gact_hash_info);
if (unlikely(!pc)) if (IS_ERR(pc))
return -ENOMEM; return PTR_ERR(pc);
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else {
if (!ovr) { if (!ovr) {

View file

@ -136,8 +136,8 @@ static int tcf_ipt_init(struct nlattr *nla, struct nlattr *est,
if (!pc) { if (!pc) {
pc = tcf_hash_create(index, est, a, sizeof(*ipt), bind, pc = tcf_hash_create(index, est, a, sizeof(*ipt), bind,
&ipt_idx_gen, &ipt_hash_info); &ipt_idx_gen, &ipt_hash_info);
if (unlikely(!pc)) if (IS_ERR(pc))
return -ENOMEM; return PTR_ERR(pc);
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else {
if (!ovr) { if (!ovr) {

View file

@ -105,8 +105,8 @@ static int tcf_mirred_init(struct nlattr *nla, struct nlattr *est,
return -EINVAL; return -EINVAL;
pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind, pc = tcf_hash_create(parm->index, est, a, sizeof(*m), bind,
&mirred_idx_gen, &mirred_hash_info); &mirred_idx_gen, &mirred_hash_info);
if (unlikely(!pc)) if (IS_ERR(pc))
return -ENOMEM; return PTR_ERR(pc);
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else {
if (!ovr) { if (!ovr) {

View file

@ -68,8 +68,8 @@ static int tcf_nat_init(struct nlattr *nla, struct nlattr *est,
if (!pc) { if (!pc) {
pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind, pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind,
&nat_idx_gen, &nat_hash_info); &nat_idx_gen, &nat_hash_info);
if (unlikely(!pc)) if (IS_ERR(pc))
return -ENOMEM; return PTR_ERR(pc);
p = to_tcf_nat(pc); p = to_tcf_nat(pc);
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else {

View file

@ -68,8 +68,8 @@ static int tcf_pedit_init(struct nlattr *nla, struct nlattr *est,
return -EINVAL; return -EINVAL;
pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind, pc = tcf_hash_create(parm->index, est, a, sizeof(*p), bind,
&pedit_idx_gen, &pedit_hash_info); &pedit_idx_gen, &pedit_hash_info);
if (unlikely(!pc)) if (IS_ERR(pc))
return -ENOMEM; return PTR_ERR(pc);
p = to_pedit(pc); p = to_pedit(pc);
keys = kmalloc(ksize, GFP_KERNEL); keys = kmalloc(ksize, GFP_KERNEL);
if (keys == NULL) { if (keys == NULL) {

View file

@ -124,8 +124,8 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,
if (!pc) { if (!pc) {
pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind, pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind,
&simp_idx_gen, &simp_hash_info); &simp_idx_gen, &simp_hash_info);
if (unlikely(!pc)) if (IS_ERR(pc))
return -ENOMEM; return PTR_ERR(pc);
d = to_defact(pc); d = to_defact(pc);
ret = alloc_defdata(d, defdata); ret = alloc_defdata(d, defdata);

View file

@ -104,8 +104,8 @@ static int tcf_skbedit_init(struct nlattr *nla, struct nlattr *est,
if (!pc) { if (!pc) {
pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind, pc = tcf_hash_create(parm->index, est, a, sizeof(*d), bind,
&skbedit_idx_gen, &skbedit_hash_info); &skbedit_idx_gen, &skbedit_hash_info);
if (unlikely(!pc)) if (IS_ERR(pc))
return -ENOMEM; return PTR_ERR(pc);
d = to_skbedit(pc); d = to_skbedit(pc);
ret = ACT_P_CREATED; ret = ACT_P_CREATED;