return NULL;
}
-static int dp_genl_del(struct sk_buff *skb, struct genl_info *info)
+static struct datapath *
+lookup_dp(struct genl_info *info)
{
int dp_idx = info->attrs[DP_GENL_A_DP_IDX] ?
nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]) : -1;
const char *dp_name = info->attrs[DP_GENL_A_DP_NAME] ?
nla_data(info->attrs[DP_GENL_A_DP_NAME]) : NULL;
struct datapath *dp = NULL;
- int err;
if ((dp_idx == -1) && (!dp_name))
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
- if (dp_idx != -1)
+ if (dp_idx != -1) {
dp = dp_get_by_idx(dp_idx);
+ if (!dp)
+ return ERR_PTR(-ENOENT);
+ }
if (dp_name) {
- struct datapath *dp_n;
- dp_n = dp_get_by_name(dp_name);
+ struct datapath *dp_n = dp_get_by_name(dp_name);
if (dp && dp != dp_n)
- return -EINVAL;
+ return ERR_PTR(-EINVAL);
dp = dp_n;
}
- if (!dp)
- err = -ENOENT;
+ return dp ? dp : ERR_PTR(-ENOENT);
+}
+
+static int dp_genl_del(struct sk_buff *skb, struct genl_info *info)
+{
+ struct datapath *dp;
+ int err;
+
+ dp = lookup_dp(info);
+ if (IS_ERR(dp))
+ err = PTR_ERR(dp);
else {
del_dp(dp);
err = 0;
{
struct datapath *dp;
struct sk_buff *ans_skb = NULL;
- int err = -ENOMEM;
- int dp_idx = info->attrs[DP_GENL_A_DP_IDX] ?
- nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]) : -1;
- const char *dp_name = info->attrs[DP_GENL_A_DP_NAME] ?
- nla_data(info->attrs[DP_GENL_A_DP_NAME]) : NULL;
-
- if ((dp_idx == -1) && (!dp_name))
- return -EINVAL;
+ int err;
rcu_read_lock();
- if (dp_idx == -1)
- dp = dp_get_by_name(dp_name);
- else
- dp = dp_get_by_idx(dp_idx);
-
- if (!dp)
- err = -ENOENT;
+ dp = lookup_dp(info);
+ if (IS_ERR(dp))
+ err = PTR_ERR(dp);
else {
void *data;
ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
err = -ENOMEM;
goto err;
}
+ err = -ENOMEM;
data = genlmsg_put_reply(ans_skb, info, &dp_genl_family,
0, DP_GENL_C_QUERY_DP);
- if (data == NULL) {
- err = -ENOMEM;
+ if (data == NULL)
goto err;
- }
NLA_PUT_U32(ans_skb, DP_GENL_A_DP_IDX, dp->dp_idx);
NLA_PUT_STRING(ans_skb, DP_GENL_A_DP_NAME, dp->netdev->name);
NLA_PUT_U32(ans_skb, DP_GENL_A_MC_GROUP, mc_group.id);
struct net_device *port;
int err;
- if (!info->attrs[DP_GENL_A_DP_IDX] || !info->attrs[DP_GENL_A_PORTNAME])
+ if (!info->attrs[DP_GENL_A_PORTNAME])
return -EINVAL;
/* Get datapath. */
- dp = dp_get_by_idx(nla_get_u32(info->attrs[DP_GENL_A_DP_IDX]));
- if (!dp) {
- err = -ENOENT;
+ dp = lookup_dp(info);
+ if (IS_ERR(dp)) {
+ err = PTR_ERR(dp);
goto out;
}