Skip to content

Commit

Permalink
[NET_SCHED]: Propagate nla_parse return value
Browse files Browse the repository at this point in the history
nla_parse() returns more detailed errno codes, propagate them back on
error.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
kaber authored and davem330 committed Jan 28, 2008
1 parent ab27cfb commit cee6372
Show file tree
Hide file tree
Showing 25 changed files with 171 additions and 60 deletions.
29 changes: 18 additions & 11 deletions net/sched/act_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,18 @@ struct tc_action *tcf_action_init_1(struct nlattr *nla, struct nlattr *est,
struct nlattr *kind;
int err;

err = -EINVAL;

if (name == NULL) {
if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0)
err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
if (err < 0)
goto err_out;
err = -EINVAL;
kind = tb[TCA_ACT_KIND];
if (kind == NULL)
goto err_out;
if (nla_strlcpy(act_name, kind, IFNAMSIZ) >= IFNAMSIZ)
goto err_out;
} else {
err = -EINVAL;
if (strlcpy(act_name, name, IFNAMSIZ) >= IFNAMSIZ)
goto err_out;
}
Expand Down Expand Up @@ -548,10 +549,12 @@ struct tc_action *tcf_action_init(struct nlattr *nla, struct nlattr *est,
{
struct nlattr *tb[TCA_ACT_MAX_PRIO+1];
struct tc_action *head = NULL, *act, *act_prev = NULL;
int err;
int i;

if (nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL) < 0)
return ERR_PTR(-EINVAL);
err = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
if (err < 0)
return ERR_PTR(err);

for (i = 1; i <= TCA_ACT_MAX_PRIO && tb[i]; i++) {
act = tcf_action_init_1(tb[i], est, name, ovr, bind);
Expand Down Expand Up @@ -674,10 +677,11 @@ tcf_action_get_1(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
int index;
int err;

err = -EINVAL;
if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0)
err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
if (err < 0)
goto err_out;

err = -EINVAL;
if (tb[TCA_ACT_INDEX] == NULL ||
nla_len(tb[TCA_ACT_INDEX]) < sizeof(index))
goto err_out;
Expand Down Expand Up @@ -759,9 +763,11 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)

b = skb_tail_pointer(skb);

if (nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL) < 0)
err = nla_parse_nested(tb, TCA_ACT_MAX, nla, NULL);
if (err < 0)
goto err_out;

err = -EINVAL;
kind = tb[TCA_ACT_KIND];
a->ops = tc_lookup_action(kind);
if (a->ops == NULL)
Expand Down Expand Up @@ -804,12 +810,13 @@ static int tca_action_flush(struct nlattr *nla, struct nlmsghdr *n, u32 pid)
static int
tca_action_gd(struct nlattr *nla, struct nlmsghdr *n, u32 pid, int event)
{
int i, ret = 0;
int i, ret;
struct nlattr *tb[TCA_ACT_MAX_PRIO+1];
struct tc_action *head = NULL, *act, *act_prev = NULL;

if (nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL) < 0)
return -EINVAL;
ret = nla_parse_nested(tb, TCA_ACT_MAX_PRIO, nla, NULL);
if (ret < 0)
return ret;

if (event == RTM_DELACTION && n->nlmsg_flags&NLM_F_ROOT) {
if (tb[0] != NULL && tb[1] == NULL)
Expand Down
7 changes: 6 additions & 1 deletion net/sched/act_gact.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ static int tcf_gact_init(struct nlattr *nla, struct nlattr *est,
struct tcf_gact *gact;
struct tcf_common *pc;
int ret = 0;
int err;

if (nla == NULL || nla_parse_nested(tb, TCA_GACT_MAX, nla, NULL) < 0)
if (nla == NULL)
return -EINVAL;

err = nla_parse_nested(tb, TCA_GACT_MAX, nla, NULL);
if (err < 0)
return err;

if (tb[TCA_GACT_PARMS] == NULL ||
nla_len(tb[TCA_GACT_PARMS]) < sizeof(*parm))
return -EINVAL;
Expand Down
6 changes: 5 additions & 1 deletion net/sched/act_ipt.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ static int tcf_ipt_init(struct nlattr *nla, struct nlattr *est,
u32 hook = 0;
u32 index = 0;

if (nla == NULL || nla_parse_nested(tb, TCA_IPT_MAX, nla, NULL) < 0)
if (nla == NULL)
return -EINVAL;

err = nla_parse_nested(tb, TCA_IPT_MAX, nla, NULL);
if (err < 0)
return err;

if (tb[TCA_IPT_HOOK] == NULL ||
nla_len(tb[TCA_IPT_HOOK]) < sizeof(u32))
return -EINVAL;
Expand Down
8 changes: 6 additions & 2 deletions net/sched/act_mirred.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ static int tcf_mirred_init(struct nlattr *nla, struct nlattr *est,
struct tcf_mirred *m;
struct tcf_common *pc;
struct net_device *dev = NULL;
int ret = 0;
int ret = 0, err;
int ok_push = 0;

if (nla == NULL || nla_parse_nested(tb, TCA_MIRRED_MAX, nla, NULL) < 0)
if (nla == NULL)
return -EINVAL;

err = nla_parse_nested(tb, TCA_MIRRED_MAX, nla, NULL);
if (err < 0)
return err;

if (tb[TCA_MIRRED_PARMS] == NULL ||
nla_len(tb[TCA_MIRRED_PARMS]) < sizeof(*parm))
return -EINVAL;
Expand Down
8 changes: 6 additions & 2 deletions net/sched/act_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ static int tcf_nat_init(struct nlattr *nla, struct nlattr *est,
{
struct nlattr *tb[TCA_NAT_MAX + 1];
struct tc_nat *parm;
int ret = 0;
int ret = 0, err;
struct tcf_nat *p;
struct tcf_common *pc;

if (nla == NULL || nla_parse_nested(tb, TCA_NAT_MAX, nla, NULL) < 0)
if (nla == NULL)
return -EINVAL;

err = nla_parse_nested(tb, TCA_NAT_MAX, nla, NULL);
if (err < 0)
return err;

if (tb[TCA_NAT_PARMS] == NULL ||
nla_len(tb[TCA_NAT_PARMS]) < sizeof(*parm))
return -EINVAL;
Expand Down
8 changes: 6 additions & 2 deletions net/sched/act_pedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ static int tcf_pedit_init(struct nlattr *nla, struct nlattr *est,
{
struct nlattr *tb[TCA_PEDIT_MAX + 1];
struct tc_pedit *parm;
int ret = 0;
int ret = 0, err;
struct tcf_pedit *p;
struct tcf_common *pc;
struct tc_pedit_key *keys = NULL;
int ksize;

if (nla == NULL || nla_parse_nested(tb, TCA_PEDIT_MAX, nla, NULL) < 0)
if (nla == NULL)
return -EINVAL;

err = nla_parse_nested(tb, TCA_PEDIT_MAX, nla, NULL);
if (err < 0)
return err;

if (tb[TCA_PEDIT_PARMS] == NULL ||
nla_len(tb[TCA_PEDIT_PARMS]) < sizeof(*parm))
return -EINVAL;
Expand Down
6 changes: 5 additions & 1 deletion net/sched/act_police.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ static int tcf_act_police_locate(struct nlattr *nla, struct nlattr *est,
struct qdisc_rate_table *R_tab = NULL, *P_tab = NULL;
int size;

if (nla == NULL || nla_parse_nested(tb, TCA_POLICE_MAX, nla, NULL) < 0)
if (nla == NULL)
return -EINVAL;

err = nla_parse_nested(tb, TCA_POLICE_MAX, nla, NULL);
if (err < 0)
return err;

if (tb[TCA_POLICE_TBF] == NULL)
return -EINVAL;
size = nla_len(tb[TCA_POLICE_TBF]);
Expand Down
8 changes: 6 additions & 2 deletions net/sched/act_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,15 @@ static int tcf_simp_init(struct nlattr *nla, struct nlattr *est,
struct tcf_common *pc;
void *defdata;
u32 datalen = 0;
int ret = 0;
int ret = 0, err;

if (nla == NULL || nla_parse_nested(tb, TCA_DEF_MAX, nla, NULL) < 0)
if (nla == NULL)
return -EINVAL;

err = nla_parse_nested(tb, TCA_DEF_MAX, nla, NULL);
if (err < 0)
return err;

if (tb[TCA_DEF_PARMS] == NULL ||
nla_len(tb[TCA_DEF_PARMS]) < sizeof(*parm))
return -EINVAL;
Expand Down
7 changes: 4 additions & 3 deletions net/sched/cls_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,17 @@ static inline int basic_set_parms(struct tcf_proto *tp, struct basic_filter *f,
static int basic_change(struct tcf_proto *tp, unsigned long base, u32 handle,
struct nlattr **tca, unsigned long *arg)
{
int err = -EINVAL;
int err;
struct basic_head *head = (struct basic_head *) tp->root;
struct nlattr *tb[TCA_BASIC_MAX + 1];
struct basic_filter *f = (struct basic_filter *) *arg;

if (tca[TCA_OPTIONS] == NULL)
return -EINVAL;

if (nla_parse_nested(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS], NULL) < 0)
return -EINVAL;
err = nla_parse_nested(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS], NULL);
if (err < 0)
return err;

if (f != NULL) {
if (handle && f->handle != handle)
Expand Down
5 changes: 3 additions & 2 deletions net/sched/cls_fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ static int fw_change(struct tcf_proto *tp, unsigned long base,
if (!opt)
return handle ? -EINVAL : 0;

if (nla_parse_nested(tb, TCA_FW_MAX, opt, NULL) < 0)
return -EINVAL;
err = nla_parse_nested(tb, TCA_FW_MAX, opt, NULL);
if (err < 0)
return err;

if (f != NULL) {
if (f->id != handle && handle)
Expand Down
5 changes: 3 additions & 2 deletions net/sched/cls_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,9 @@ static int route4_change(struct tcf_proto *tp, unsigned long base,
if (opt == NULL)
return handle ? -EINVAL : 0;

if (nla_parse_nested(tb, TCA_ROUTE4_MAX, opt, NULL) < 0)
return -EINVAL;
err = nla_parse_nested(tb, TCA_ROUTE4_MAX, opt, NULL);
if (err < 0)
return err;

if ((f = (struct route4_filter*)*arg) != NULL) {
if (f->handle != handle && handle)
Expand Down
5 changes: 3 additions & 2 deletions net/sched/cls_rsvp.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,9 @@ static int rsvp_change(struct tcf_proto *tp, unsigned long base,
if (opt == NULL)
return handle ? -EINVAL : 0;

if (nla_parse_nested(tb, TCA_RSVP_MAX, opt, NULL) < 0)
return -EINVAL;
err = nla_parse_nested(tb, TCA_RSVP_MAX, opt, NULL);
if (err < 0)
return err;

err = tcf_exts_validate(tp, tb, tca[TCA_RATE-1], &e, &rsvp_ext_map);
if (err < 0)
Expand Down
6 changes: 4 additions & 2 deletions net/sched/cls_tcindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ tcindex_change(struct tcf_proto *tp, unsigned long base, u32 handle,
struct nlattr *tb[TCA_TCINDEX_MAX + 1];
struct tcindex_data *p = PRIV(tp);
struct tcindex_filter_result *r = (struct tcindex_filter_result *) *arg;
int err;

pr_debug("tcindex_change(tp %p,handle 0x%08x,tca %p,arg %p),opt %p,"
"p %p,r %p,*arg 0x%lx\n",
Expand All @@ -358,8 +359,9 @@ tcindex_change(struct tcf_proto *tp, unsigned long base, u32 handle,
if (!opt)
return 0;

if (nla_parse_nested(tb, TCA_TCINDEX_MAX, opt, NULL) < 0)
return -EINVAL;
err = nla_parse_nested(tb, TCA_TCINDEX_MAX, opt, NULL);
if (err < 0)
return err;

return tcindex_set_parms(tp, base, handle, p, r, tb, tca[TCA_RATE]);
}
Expand Down
5 changes: 3 additions & 2 deletions net/sched/cls_u32.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,9 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
if (opt == NULL)
return handle ? -EINVAL : 0;

if (nla_parse_nested(tb, TCA_U32_MAX, opt, NULL) < 0)
return -EINVAL;
err = nla_parse_nested(tb, TCA_U32_MAX, opt, NULL);
if (err < 0)
return err;

if ((n = (struct tc_u_knode*)*arg) != NULL) {
if (TC_U32_KEY(n->handle) == 0)
Expand Down
6 changes: 4 additions & 2 deletions net/sched/em_meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,14 +749,16 @@ static inline int meta_is_supported(struct meta_value *val)
static int em_meta_change(struct tcf_proto *tp, void *data, int len,
struct tcf_ematch *m)
{
int err = -EINVAL;
int err;
struct nlattr *tb[TCA_EM_META_MAX + 1];
struct tcf_meta_hdr *hdr;
struct meta_match *meta = NULL;

if (nla_parse(tb, TCA_EM_META_MAX, data, len, NULL) < 0)
err = nla_parse(tb, TCA_EM_META_MAX, data, len, NULL);
if (err < 0)
goto errout;

err = -EINVAL;
if (tb[TCA_EM_META_HDR] == NULL ||
nla_len(tb[TCA_EM_META_HDR]) < sizeof(*hdr))
goto errout;
Expand Down
6 changes: 4 additions & 2 deletions net/sched/ematch.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static int tcf_em_validate(struct tcf_proto *tp,
int tcf_em_tree_validate(struct tcf_proto *tp, struct nlattr *nla,
struct tcf_ematch_tree *tree)
{
int idx, list_len, matches_len, err = -EINVAL;
int idx, list_len, matches_len, err;
struct nlattr *tb[TCA_EMATCH_TREE_MAX + 1];
struct nlattr *rt_match, *rt_hdr, *rt_list;
struct tcf_ematch_tree_hdr *tree_hdr;
Expand All @@ -312,9 +312,11 @@ int tcf_em_tree_validate(struct tcf_proto *tp, struct nlattr *nla,
return 0;
}

if (nla_parse_nested(tb, TCA_EMATCH_TREE_MAX, nla, NULL) < 0)
err = nla_parse_nested(tb, TCA_EMATCH_TREE_MAX, nla, NULL);
if (err < 0)
goto errout;

err = -EINVAL;
rt_hdr = tb[TCA_EMATCH_TREE_HDR];
rt_list = tb[TCA_EMATCH_TREE_LIST];

Expand Down
6 changes: 5 additions & 1 deletion net/sched/sch_atm.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,12 @@ static int atm_tc_change(struct Qdisc *sch, u32 classid, u32 parent,
*/
if (flow)
return -EBUSY;
if (opt == NULL || nla_parse_nested(tb, TCA_ATM_MAX, opt, NULL))
if (opt == NULL)
return -EINVAL;
error = nla_parse_nested(tb, TCA_ATM_MAX, opt, NULL);
if (error < 0)
return error;

if (!tb[TCA_ATM_FD] || nla_len(tb[TCA_ATM_FD]) < sizeof(fd))
return -EINVAL;
fd = *(int *)nla_data(tb[TCA_ATM_FD]);
Expand Down
14 changes: 11 additions & 3 deletions net/sched/sch_cbq.c
Original file line number Diff line number Diff line change
Expand Up @@ -1382,9 +1382,13 @@ static int cbq_init(struct Qdisc *sch, struct nlattr *opt)
struct cbq_sched_data *q = qdisc_priv(sch);
struct nlattr *tb[TCA_CBQ_MAX + 1];
struct tc_ratespec *r;
int err;

err = nla_parse_nested(tb, TCA_CBQ_MAX, opt, NULL);
if (err < 0)
return err;

if (nla_parse_nested(tb, TCA_CBQ_MAX, opt, NULL) < 0 ||
tb[TCA_CBQ_RTAB] == NULL || tb[TCA_CBQ_RATE] == NULL ||
if (tb[TCA_CBQ_RTAB] == NULL || tb[TCA_CBQ_RATE] == NULL ||
nla_len(tb[TCA_CBQ_RATE]) < sizeof(struct tc_ratespec))
return -EINVAL;

Expand Down Expand Up @@ -1764,9 +1768,13 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
struct cbq_class *parent;
struct qdisc_rate_table *rtab = NULL;

if (opt==NULL || nla_parse_nested(tb, TCA_CBQ_MAX, opt, NULL))
if (opt == NULL)
return -EINVAL;

err = nla_parse_nested(tb, TCA_CBQ_MAX, opt, NULL);
if (err < 0)
return err;

if (tb[TCA_CBQ_OVL_STRATEGY] &&
nla_len(tb[TCA_CBQ_OVL_STRATEGY]) < sizeof(struct tc_cbq_ovl))
return -EINVAL;
Expand Down
Loading

0 comments on commit cee6372

Please sign in to comment.