Simplify lookup_dp() now that we can assume that dp_name is null-terminated.
authorBen Pfaff <blp@nicira.com>
Tue, 30 Dec 2008 20:40:11 +0000 (12:40 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 30 Dec 2008 21:05:15 +0000 (13:05 -0800)
datapath/datapath.c

index d9184b656ed4e36fa7bb5140113d163867a628fb..e10b520696cd900c67085cd4ef7df5d79c0c3486 100644 (file)
@@ -1135,13 +1135,9 @@ struct datapath *dp_get_by_idx(int dp_idx)
 struct datapath *dp_get_by_name(const char *dp_name)
 {
        int i;
-
-       if (!dp_name || (strlen(dp_name) >= sizeof(dps[0]->netdev->name)))
-               return NULL;
-
        for (i=0; i<DP_MAX; i++) {
                struct datapath *dp = rcu_dereference(dps[i]);
-               if (dp && !strncmp(dp->netdev->name, dp_name, IFNAMSIZ))
+               if (dp && !strcmp(dp->netdev->name, dp_name))
                        return dp;
        }
        return NULL;
@@ -1154,25 +1150,21 @@ lookup_dp(struct genl_info *info)
                        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;
-
-       if ((dp_idx == -1) && (!dp_name))
-               return ERR_PTR(-EINVAL);
 
        if (dp_idx != -1) {
-               dp = dp_get_by_idx(dp_idx);
+               struct datapath *dp = dp_get_by_idx(dp_idx);
                if (!dp)
                        return ERR_PTR(-ENOENT);
-       }
-
-       if (dp_name) {
-               struct datapath *dp_n = dp_get_by_name(dp_name);
-               if (dp && dp != dp_n)
+               else if (dp_name && strcmp(dp->netdev->name, dp_name))
                        return ERR_PTR(-EINVAL);
-               dp = dp_n;
+               else
+                       return dp;
+       } else if (dp_name) {
+               struct datapath *dp = dp_get_by_name(dp_name);
+               return dp ? dp : ERR_PTR(-ENOENT);
+       } else {
+               return ERR_PTR(-EINVAL);
        }
-
-       return dp ? dp : ERR_PTR(-ENOENT);
 }
 
 static int dp_genl_del(struct sk_buff *skb, struct genl_info *info)