dcbnl: more informed return values for new dcbnl routines

More accurate return values for the following (new) dcbnl routines:
dcbnl_getdcbx()
dcbnl_setdcbx()
dcbnl_getfeatcfg()
dcbnl_setfeatcfg()

Signed-off-by: Shmulik Ravid <shmulikr@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Shmulik Ravid 2011-01-03 08:04:59 +00:00 committed by David S. Miller
parent 87e609760b
commit 7f891cf1fc

View File

@ -1286,10 +1286,10 @@ nlmsg_failure:
static int dcbnl_getdcbx(struct net_device *netdev, struct nlattr **tb, static int dcbnl_getdcbx(struct net_device *netdev, struct nlattr **tb,
u32 pid, u32 seq, u16 flags) u32 pid, u32 seq, u16 flags)
{ {
int ret = -EINVAL; int ret;
if (!netdev->dcbnl_ops->getdcbx) if (!netdev->dcbnl_ops->getdcbx)
return ret; return -EOPNOTSUPP;
ret = dcbnl_reply(netdev->dcbnl_ops->getdcbx(netdev), RTM_GETDCB, ret = dcbnl_reply(netdev->dcbnl_ops->getdcbx(netdev), RTM_GETDCB,
DCB_CMD_GDCBX, DCB_ATTR_DCBX, pid, seq, flags); DCB_CMD_GDCBX, DCB_ATTR_DCBX, pid, seq, flags);
@ -1300,11 +1300,14 @@ static int dcbnl_getdcbx(struct net_device *netdev, struct nlattr **tb,
static int dcbnl_setdcbx(struct net_device *netdev, struct nlattr **tb, static int dcbnl_setdcbx(struct net_device *netdev, struct nlattr **tb,
u32 pid, u32 seq, u16 flags) u32 pid, u32 seq, u16 flags)
{ {
int ret = -EINVAL; int ret;
u8 value; u8 value;
if (!tb[DCB_ATTR_DCBX] || !netdev->dcbnl_ops->setdcbx) if (!netdev->dcbnl_ops->setdcbx)
return ret; return -EOPNOTSUPP;
if (!tb[DCB_ATTR_DCBX])
return -EINVAL;
value = nla_get_u8(tb[DCB_ATTR_DCBX]); value = nla_get_u8(tb[DCB_ATTR_DCBX]);
@ -1323,23 +1326,23 @@ static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlattr **tb,
struct dcbmsg *dcb; struct dcbmsg *dcb;
struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest; struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest;
u8 value; u8 value;
int ret = -EINVAL; int ret, i;
int i;
int getall = 0; int getall = 0;
if (!tb[DCB_ATTR_FEATCFG] || !netdev->dcbnl_ops->getfeatcfg) if (!netdev->dcbnl_ops->getfeatcfg)
return ret; return -EOPNOTSUPP;
if (!tb[DCB_ATTR_FEATCFG])
return -EINVAL;
ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG], ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
dcbnl_featcfg_nest); dcbnl_featcfg_nest);
if (ret) { if (ret)
ret = -EINVAL;
goto err_out; goto err_out;
}
dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!dcbnl_skb) { if (!dcbnl_skb) {
ret = -EINVAL; ret = -ENOBUFS;
goto err_out; goto err_out;
} }
@ -1351,8 +1354,8 @@ static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlattr **tb,
nest = nla_nest_start(dcbnl_skb, DCB_ATTR_FEATCFG); nest = nla_nest_start(dcbnl_skb, DCB_ATTR_FEATCFG);
if (!nest) { if (!nest) {
ret = -EINVAL; ret = -EMSGSIZE;
goto err; goto nla_put_failure;
} }
if (data[DCB_FEATCFG_ATTR_ALL]) if (data[DCB_FEATCFG_ATTR_ALL])
@ -1363,30 +1366,22 @@ static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlattr **tb,
continue; continue;
ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value); ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value);
if (!ret) { if (!ret)
ret = nla_put_u8(dcbnl_skb, i, value); ret = nla_put_u8(dcbnl_skb, i, value);
if (ret) { if (ret) {
nla_nest_cancel(dcbnl_skb, nest); nla_nest_cancel(dcbnl_skb, nest);
ret = -EINVAL; goto nla_put_failure;
goto err; }
}
} else
goto err;
} }
nla_nest_end(dcbnl_skb, nest); nla_nest_end(dcbnl_skb, nest);
nlmsg_end(dcbnl_skb, nlh); nlmsg_end(dcbnl_skb, nlh);
ret = rtnl_unicast(dcbnl_skb, &init_net, pid); return rtnl_unicast(dcbnl_skb, &init_net, pid);
if (ret) { nla_put_failure:
ret = -EINVAL; nlmsg_cancel(dcbnl_skb, nlh);
goto err_out;
}
return 0;
nlmsg_failure: nlmsg_failure:
err:
kfree_skb(dcbnl_skb); kfree_skb(dcbnl_skb);
err_out: err_out:
return ret; return ret;
@ -1396,20 +1391,20 @@ static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlattr **tb,
u32 pid, u32 seq, u16 flags) u32 pid, u32 seq, u16 flags)
{ {
struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1]; struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1];
int ret = -EINVAL; int ret, i;
u8 value; u8 value;
int i;
if (!tb[DCB_ATTR_FEATCFG] || !netdev->dcbnl_ops->setfeatcfg) if (!netdev->dcbnl_ops->setfeatcfg)
return ret; return -ENOTSUPP;
if (!tb[DCB_ATTR_FEATCFG])
return -EINVAL;
ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG], ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
dcbnl_featcfg_nest); dcbnl_featcfg_nest);
if (ret) { if (ret)
ret = -EINVAL;
goto err; goto err;
}
for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) { for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
if (data[i] == NULL) if (data[i] == NULL)
@ -1420,14 +1415,12 @@ static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlattr **tb,
ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value); ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value);
if (ret) if (ret)
goto operr; goto err;
} }
operr:
ret = dcbnl_reply(!!ret, RTM_SETDCB, DCB_CMD_SFEATCFG,
DCB_ATTR_FEATCFG, pid, seq, flags);
err: err:
dcbnl_reply(ret, RTM_SETDCB, DCB_CMD_SFEATCFG, DCB_ATTR_FEATCFG,
pid, seq, flags);
return ret; return ret;
} }